Reputation: 33956
I want to set a simple condition inside the loop so that the code inside is only run if any input is focused or if any element in the body is focused. How do I do each thing?
setInterval(function(){
document.getElementById('clickMe').style.display= "block";
}, 1000 );
thanks
Upvotes: 1
Views: 199
Reputation: 147403
Use the W3C document.activeElement proprety to see which element is focused (also documented at MDN).
Note that this property is introduced in HTML5 and may not be widely implemented, so test for support and expect it not to be supported in a reasonable percentage of clients.
Upvotes: 1