Подтвердить что ты не робот

Обнаружение Javascript, если вход сфокусирован

Как определить, когда событие .click срабатывает, если текстовая область уже сфокусирована?

У меня есть этот JQuery:

$(".status").on("click","textarea",function(){
        if ($(this) == "focused") {
            // fire this step
        }else{
            $(this).focus();
            // fire this step
    }
4b9b3361

Ответ 1

С чистым javascript:

this === document.activeElement // where 'this' is a dom object

или с псевдо-селектором jquery :focus.

$(this).is(':focus');

Ответ 2

Использование jQuery .is( ": focus" )

$(".status").on("click","textarea",function(){
        if ($(this).is( ":focus" )) {
            // fire this step
        }else{
                    $(this).focus();
            // fire this step
    }