What I want is when checkbox1 is selected both checkbox labelled 1 will get selected and background will be removed
for eg if i select checkbox1 it should select both checkbox labelled checkbox1
What I want is when checkbox1 is selected both checkbox labelled 1 will get selected and background will be removed
for eg if i select checkbox1 it should select both checkbox labelled checkbox1
The problem is that searching for ID $("#somethin") is not possible to select more than one element. IF you search for class, then your example works.. well, with some minor changes :)
$(document).ready(function() {
$('input[type=checkbox]').change(function(){
var pos;
pos = this.id;
// global hook - unblock UI when ajax request completes
$(document).ajaxStop($.unblockUI);
if($(this).prop("checked")) {
$("."+pos).parent().removeClass("highlight");
$("."+pos).prop('checked', true)
//ajax to add uni
} else {
//ajax to remove uni
$("."+pos).parent().addClass("highlight");
$("."+pos).prop('checked', false)
}
});
});
You can't have multiple DOM elements with the same id.
See this fiddle for a working example, but it's not as generic as you may need.
Select multiple elements using class. You can try this..
<script language="javascript" type="text/javascript">
$(function () {
$("#checkbox1").click(function () {
$('.case').attr('checked', this.checked);
});
});
</script>
and your html code will be like below
<div>
<table>
<tr>
<td><input type="checkbox" id="checkbox1" class="highlight"/></td>
<td>Item1</td>
<td>value</td>
</tr>
<tr>
<td align="center"><input type="checkbox" class="case" name="case" value="1"/></td>
<td>Item2</td>
<td>value</td>
</tr>
</table>
</div>