Advertisement
trentjs

Add Event By ID to Read Data Attribute

Nov 17th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // <button id="btn01" data-info="some-info">Click Button</button>
  2.  
  3. var click00 = document.getElementById("btn01");
  4. click00.addEventListener("click", doEventClick)
  5.  
  6. function doEventClick(event){
  7.     var thisId = event.target.id;
  8.     var thisInfo = event.target.getAttribute("data-info");
  9.     console.log(thisId + " : " + thisInfo);
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement