Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

event listener to elements with class

document.querySelectorAll('.some-class').forEach(item => {
  item.addEventListener('click', event => {
    //handle click
  })
})
Comment

click listener on by class name in javascript

var elements = document.getElementsByClassName("classname");

var myFunction = function() {
    var attribute = this.getAttribute("data-myattribute");
    alert(attribute);
};

for (var i = 0; i < elements.length; i++) {
    elements[i].addEventListener('click', myFunction, false);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: React + modal: input field auto focus 
Javascript :: javascript convert number to string 
Javascript :: activate es6 module node package.json 
Javascript :: get device type javascript 
Javascript :: js create element 
Javascript :: how to convert string to int a array in javascript 
Javascript :: How To Hide Back Button In React/React Native Navigation 
Javascript :: javascript clear text in textarea 
Javascript :: python json string to object 
Javascript :: react map array limit 
Javascript :: how to clear pod cache in react native 
Javascript :: how to get date time day year in javscript 
Javascript :: install node js lts ubuntu 18.04 
Javascript :: jquery cancel ajax request on click 
Javascript :: tailwind nextjs 
Javascript :: usenavigate 
Javascript :: javascript substring last character 
Javascript :: jquery loop through list element 
Javascript :: adding font awesome to npm or react 
Javascript :: make the log do a jump in line js 
Javascript :: js input text set value 
Javascript :: how to click button programmatically in jquery 
Javascript :: js create date from string 
Javascript :: jquery get data-id 
Javascript :: express send raw html 
Javascript :: javascript json download 
Javascript :: how to check file extension in node js 
Javascript :: wait for the dom to load javascript 
Javascript :: document ready javacsript 
Javascript :: angular input change event 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =