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, t开发者_运维技巧hen ancestor it somehow?
$("#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);
});
$("#abc123 input[type=checkbox]").each(function() {
$(this).dosomething();
});
Use a onkeydown
event... I recommend the tab key which is keycode
"9"
$(document).keydown(function(e){
if(event.keyCode == '9'){
...
}
Inside the if statement
you'll need a nested if statement
that checks which element is in focus and then assigns focus to the next element like this :
document.div.id.focus();
You didn't label where #abc123
is in your code. Also, do the <td>
tags have any identification? The following may work.
$("#abc123 input:checkbox").each(function(i) {
id = $(this).closest('td').next('td').text();
$(this).attr('id', id);
});
I am not sure how deep your <div id="abc123">
is in the <td>
so I used the closest() method to get to the cell wrapper. If it is only 1 deep, i.e. there is no <div>
as it appears in your code, then you can just use parent(). Good luck.
精彩评论