eye eye - 1 year ago 149
jQuery Question

jQuery - find all IDs in a class

Let's say i have a html table like this:

<tr id="a" class="red"><td>test</td></tr>
<tr id="b" class="red"><td>test</td></tr>
<tr id="c" class="red"><td>test</td></tr>
<tr id="d" class="red"><td>test</td></tr>
<tr id="e" class="green"><td>test</td></tr>
<tr id="f" class="blue"><td>test</td></tr>

How can i loop through/get all ids of class "red" using jQuery?

Answer Source

Use .each()

var idArray = [];
$('.red').each(function () {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download