1document.querySelectorAll('.some-class').forEach(item => {
2 item.addEventListener('click', event => {
3 //handle click
4 })
5})
1var classname = document.getElementsByClassName("classname");
2
3var myFunction = function() {
4 var attribute = this.getAttribute("data-myattribute");
5 alert(attribute);
6};
7
8for (var i = 0; i < classname.length; i++) {
9 classname[i].addEventListener('click', myFunction, false);
10}