Let's say I have the following div that gets focus after a certain condition is met:
<div id="myID" tabindex="-1" >Some Text</div>
I want to create a handler that checks whether or not that div has focus, and when it evaluates to true/focus is on the div, do something (in the example below, print a console log):
if (document.getElementById('#myID').hasFocus()) {
$(document).keydown(function(event) {
if (event.which === 40) {
console.log('keydown pressed')
}
});
}
I'm getting an error message in the console that says:
TypeError: Cannot read property 'hasFocus' of null
Any idea what I'm doing wrong here? Maybe the way I'm passing the div Id?