Skip to content

Instantly share code, notes, and snippets.

@kulerbox
Created November 14, 2014 08:27
Show Gist options
  • Save kulerbox/a314223113c25aa394cf to your computer and use it in GitHub Desktop.
Save kulerbox/a314223113c25aa394cf to your computer and use it in GitHub Desktop.
//create an array from classes
var jsClass = document.getElementsByClassName("jsClass");
//loop through the length of the array
for (var i = 0; i < jsClass.length; i++) {
//assign a onclick event to each element
jsClass[i].onclick = function() {
//this will be the actual element. So you can use this.id to get the element's id
var thisId = this.id;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment