Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop through all checkboxes that are inside a div tag

I need to loop through all checkboxes that are inside a div tag with id #abc123

How can I do this?

$("#abc123").foreach( ???? )

Update my html row looks like:

<tr>
<td><input .../> </td>
<td>234</td>

</tr>

I need to add the value of the <td> into the ID of the checkbox.

Would I just get the parent, then ancestor it somehow?

like image 604
Blankman Avatar asked Aug 20 '10 16:08

Blankman


2 Answers

$("#abc123 input[type=checkbox]").each(function()
     {

     });

UPDATE:

Ok, Let'd see if I got this straight. Given:

<tr> 
<td><input .../> </td> 
<td>234</td> 
</tr>

You want the result to be (effectively)

<tr> 
<td><input id="abc234" .../> </td> 
<td>234</td> 
</tr>

$("td input[type=checkbox]").each(function()
{
     var id = $(this).next("td").text();
     $(this).attr("id", "abc"+ id);
});
like image 114
James Curran Avatar answered Nov 01 '22 00:11

James Curran


$("#abc123 input[type=checkbox]").each(function() {
    $(this).dosomething();
});
like image 5
Māris Kiseļovs Avatar answered Oct 31 '22 23:10

Māris Kiseļovs