简体   繁体   中英

My focus event listener is not getting triggered

When i try to fire a event listener in js for an input element it is not getting called. This is how I am trying to do it.

var el = document.getElementById(“inputEl”);

el. addEventListener('focus', (event) => {
  console.log(‘inside this block’);
});

What am I doing wrong here?

Change your js as below:

var el = document.getElementById("inputEl");

el.addEventListener('focus', (event) => {
  console.log('inside this block');
});

And also place your.js file at the bottom in your index.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM