0

There's a script running on my website but I want it to be executed only when certain element is NOT focused. Here's my general idea how it'd look

window.setInterval(function(){
   if (document.getElementById('someElement') != focused) {
   doSomething;
   }
}, 1000); 

The "someElement" is set to be editable so it can be clicked (focused).

My question is how would "!= focused" look in javascript.

Vortic
  • 75
  • 1
  • 8

2 Answers2

3

you can use document.activeElement

like this

if (document.getElementById('someElement') !== document.activeElement)
lacexd
  • 903
  • 1
  • 7
  • 22
0

Use this to check focus.............

window.setInterval(function(){
   if (document.getElementById('someElement').is(":focus") {
   doSomething;
   }
}, 1000); 
abhit
  • 973
  • 3
  • 17
  • 40