Reputation: 645
I have a set of the span tags like .
<span id="q_1" >D1</span>
<span id="q_2" >D2</span>
<span id="q_3" >D3</span>
How can i get the ids of the span tags with the help of the jquery.The numbers 1,2,3 are generated run time.so the basic structure that i have is
<span id="q_" ></span>
Upvotes: 0
Views: 180
Reputation: 3968
to get an array if ids:
var a = $.map($('span'), function(s){ return s.id; });
Upvotes: 2
Reputation: 50215
I have a feeling you're actually asking how to select all elements that have an id that starts with "q_". If so, the simplest way to do so is like this:
var qSpans = $('span[id^="q_"]');
Upvotes: 2
Reputation: 2122
$('span');
Will find all spans.
$('span').filter(function() {
return (/^q\_\d+$/i).test($(this).attr('id'));
});
Or only spans who's id matches the format
Upvotes: 1
Reputation: 9676
$("span").each(function(){
var thisId = $(this).attr('id');
// Do whatever you want with the Id, and go on to the next one.
});
:)
Upvotes: 6