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.

0

2 Answers 2

3

you can use document.activeElement

like this

if (document.getElementById('someElement') !== document.activeElement)
Sign up to request clarification or add additional context in comments.

Comments

0

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

window.setInterval(function(){
   if (document.getElementById('someElement').is(":focus") {
   doSomething;
   }
}, 1000); 

1 Comment

its only working with jquery

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.