function getIds(selector) { var a = []; $(selector).each(function() { a.push($(this).attr('id')); }); return a; } function exampleUse() { var a, i; a = getIds('.myclass'); for (i = 0; i < a.length; i++) { document.writeln('id: ' + a[i] + '<br>'); } }
Programming Tips - jQuery: get the id of every element using a certain class
Date: 2009dec16
Language: javaScript
Library: jQuery
Q. jQuery: get the id of every element using a certain class
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.