javascript class click event
var classname = document.getElementsByClassName("classname");
var myFunction = function() {
var attribute = this.getAttribute("data-myattribute");
alert(attribute);
};
for (var i = 0; i < classname.length; i++) {
classname[i].addEventListener('click', myFunction, false);
}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);
}
// If you have ES6 support you can replace your last line with:
Array.from(elements).forEach(function(element) {
element.addEventListener('click', myFunction);
});
Also in JavaScript:
- print all variables defined javascript
- javascript for loop over dictionary
- express validator always return error
- secure random nodejs
- regular expression replace a dot
- js domtokenlist to array
- javascript alert program
- smooth scroll to top jquery
- onclick send to email javascript
- deleteicon material ui improt
- javascript and python graphs for data analysis
- geoJson
- json property becoming small after retriving from .net core controller
- invalid left-hand side in assignment
- javascript find prime number
- To set the text of button using Jquery
- express and node
- sort array of objects javascript
- how to change grid size with conditional expression in react
- nodejs cronjob
- timezone in react js
- how to animate a flash in jquery
- statusbar reactnati
- mapbox blurry popup