javascript test if element has focus

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

Source

Also in JavaScript: