jQuery check element has focus
snippet in javascript

jQuery check element has focus

user7439

//test if element has focus in jQuery
if ($("#myElementID").is(":focus")) {
    //I have the focus
}

//test if element has focus in plain Javascript
var myElement = document.getElementById('myID');
if(myElement === document.activeElement){
    //myElement Has Focus
}

jQuery check element has focus

user1378

var myElement = document.getElementById('myID');
if(myElement === document.activeElement){
    //myElement Has Focus
}