Created
August 2, 2012 10:33
-
-
Save Paratron/3236143 to your computer and use it in GitHub Desktop.
Get id attribute of all elements with a certain class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Without jQuery | |
var elements = document.getElementsByClassName('clicked'), //Be careful: won't work in IE 6,7,8 | |
ids = []; | |
for(var i = 0; i < elements.length; i++){ | |
ids.push(elements[i].id); | |
} | |
console.log(ids); | |
//============================================================== | |
//With jQuery | |
var ids = []; | |
$.each($('.clicked'), function(){ | |
ids.push($(this).attr('id')); | |
}); | |
console.log(ids); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment