user63898
user63898

Reputation: 30915

How to iterate through table with and get each checkbox value

i have this table :

<table ="myTable">
<tr>
<td id="username_57">lillie</td>
<td id="text_57"/>
<td>1969-12-31</td>
<td>24.xx.84.xx</td>
<td>
<button id="edit_text_57" name="id_57">Edit</button>
<input type="checkbox" id="delit_57"/>
</td>
</tr>
<tr>
<td id="username_39">test</td>
<td id="text_39">asdasdasdsdasdasd</td>
<td>2012-06-04</td>
<td>217.xx.237.6</td>
<td>
<button id="edit_text_39" name="id_39">Edit</button>
<input type="checkbox" id="delit_39"/>
</td>
</tr>
<tr>
<td id="username_45">admin</td>
<td id="text_45">sadasdasdad</td>
<td>2012-09-04</td>
<td>217.xx.237.6</td>
<td>
<button id="edit_text_45" name="id_45">Edit</button>
<input type="checkbox" id="delit_45"/>
</td>
</tr>
</table>

i like to iterate through all the checkbox's with the id delit_* and check if its value is checked or not? how can i do this in jquery style ?

Upvotes: 0

Views: 4929

Answers (2)

jimp
jimp

Reputation: 17477

A selector can actually return the ones that are checked. Iteration is not needed.

$('input[type="checkbox"][id^="delit_"]:checked').each(function()
{
// Do something.
});

If you want checked and unchecked, simply remove the :checked part of the selector, and compare if (this.checked) { } in the .each loop.

jsFiddle: http://jsfiddle.net/jimp/rKjtr/

Upvotes: 5

Mohammed Swillam
Mohammed Swillam

Reputation: 9242

$("input[type=checkbox][id^='delit']").each(function(){
   if  (this.checked)
   {
     // do your stuff here
   }
})

Upvotes: 2

Related Questions