Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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 :: vehicle number formik validation 
Javascript :: react form on submit 
Javascript :: js object contain key 
Javascript :: while loop countdown javascript 
Javascript :: get class count in jquery 
Javascript :: display toastr warning 
Javascript :: react style ternary operator 
Javascript :: Password checking regex 
Javascript :: sort multidimensional array javascript 
Javascript :: how to find length of string in javascript without using length method 
Javascript :: how to show only time in hours and minutes only in javascript 
Javascript :: javascript add css file 
Javascript :: set bg image in react 
Javascript :: how to check if connected to internet js 
Javascript :: reload datatable ajax 
Javascript :: javascript get first character of string 
Javascript :: next js fallback 
Javascript :: money separator in javascript 
Javascript :: pad js 
Javascript :: angular add object to array 
Javascript :: local storage size check 
Javascript :: jquery change picture onclick 
Javascript :: javascript print object pretty 
Javascript :: system collections generic list to javascript array 
Javascript :: javascript is valid json string 
Javascript :: javascript: get the url without query string 
Javascript :: jquery find id with string at end 
Javascript :: js check if function exists 
Javascript :: date options js 
Javascript :: how to return 5 records instead of 10 records in datatable 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =