Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
 
PREVIOUS NEXT
Tagged: #addEventListener #call
ADD COMMENT
Topic
Name
3+2 =