I'm trying this to get the id
of each element in a class
but instead it's alerting each name of the class separately, so for class="test"
it's alerting: t
, e
, s
, t
... Any advice on how to get the each element id
that is part of the class
is appreciated, as I can't seem to figure this out.. Thanks.
$.each('test', function() {
alert(this)
});
patrick dw's answer is right on.
For kicks and giggles I thought I would post a simple way to return an array of all the IDs.
var arrayOfIds = $.map($(".myClassName"), function(n, i){
return n.id;
});
alert(arrayOfIds);
Source: Stackoverflow.com