Answers for "addEventListener call only once"

0

addEventListener call only once

var list = document.getElementsByTagName('ul')[0]

list.addEventListener('click', function(e){
  var el = e.target
  // walk up the tree until we find a LI item
  while (el && el.tagName !== 'LI') {
     el = el.parentNode
  }
  console.log('item clicked', el)
},{ once: true }) // when we use once as true, it will never call again
Posted by: Guest on June-08-2021

Code answers related to "addEventListener call only once"

Browse Popular Code Answers by Language