Jquery Check Element Has Focus

Source URL: N/A

Language: javascript

Created on: 2019-08-01 21:34:00

//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
content_copy