[jQuery] next closet or what
I am trying to get the input element from the current selection so for
instance when I check a checkbox I want the next checkbox to be
checked now I can use .next() if the checkbox is right next toeach
other but once I put a td or span it doesn't work
this doesn't work
<table >
<form method="post" id="frmOne">
<tr>
<th>Name</th>
<th>Location</th>
</tr>
<tr>
<td><input type="checkbox" class="checkbox" name="ss" value="1">
Spiraldev
<td><input type="checkbox" class="checkbox" name="ss" value="1">
Sac Town</td>
</tr>
</form>
</table>
<script>
$(document).ready(
function(){
$( "input.checkbox" ).click(
function(){
if($(this).attr('checked') == true){
$(this).next('input[type=checkbox]]').attr('checked',true)
}else{
$(this).next('[type=checkbox]]').attr('checked',false)
}
}
);
}
);
</script>
this does work
<input type="checkbox" class="checkbox" name="ss" value="1">
Spiraldev
<input type="checkbox" class="checkbox" name="ss" value="1"> Sac Town
<script>
$(document).ready(
function(){
$( "input.checkbox" ).click(
function(){
if($(this).attr('checked') == true){
$(this).next('input[type=checkbox]]').attr('checked',true)
}else{
$(this).next('[type=checkbox]]').attr('checked',false)
}
}
);
}
);
</script>
Why? And What do I need to do?