views:

68

answers:

1

Would anyone know how to loop through all ID's that being with name_

So, for example, within the markup I may have 50 id's that all start with "name_", the full ID would be like name_2, name_55, name_25, etc.

I'd like to loop through all of these getting the number.

Not really sure where to begin....... thank you!

+9  A: 

use the attribute starts with selector

$('[id^=name_]').each(function() {
    var number = this.id.split('_').pop();
});
Anurag
+1 for the most elegant solution.
James Skidmore