Búsqueda de sitios web

Javascript/jQuery detectar si un input está enfocado


¿Cómo detecto cuándo se dispara el evento .click si el área de texto ya está enfocada?

Tengo este jquery:

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

Respuesta #1

Con JavaScript puro:

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

o con el pseudo selector :focus de jQuery.

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

Artículos relacionados