Date: 2009dec16
Language: javaScript
Platform: jQuery
Q. How can get the id of every element using a certain class (using jQuery)?
A. This is the kind of thing jQuery was made for. Here is a function
that returns an array of id of all elements using a certain class.
function getIds(selector) {
var a = [];
$(selector).each(function() {
a.push(this.id);
});
return a;
}
function exampleUse() {
var a, i;
a = getIds('.myclass');
for (i = 0; i < a.length; i++) {
document.writeln('id: ' + a[i] + '<br>');
}
}
| What this info useful to you? You can donate to say thanks |
Add a comment
Sign in to add a comment