Check if input field has focus in vanilla JavaScript

Using jQuery, I can check if the input field has the same value:

if ($("...").is(":focus")) { ... } 

How can I do this without using jQuery?

+7
javascript html input focus
source share
1 answer

This question has been answered: Javascript detects input is focused.

Taken from the answer above:

 this === document.activeElement // where 'this' is a dom object 
+12
source share

All Articles