var others = $("#6");
others.click(function() {
$('input:checkbox').attr('checked',false);
$("#6").attr('checked',true);
});
I have an array of check boxes which is drawn from database. I want to uncheck other check boxes when a certain check box is ticked in my case checkbox with id #6, and it uncheck a checkbox #6 if other checkbox is check.
The code above is able to uncheck other checkbox but how can I uncheck the checkbox with id 6,once the other checkbox is check.
Eldros
5611 gold badge9 silver badges29 bronze badges
-
2"6" is not a valid ID for an element.Tim Down– Tim Down2010年05月17日 10:22:02 +00:00Commented May 17, 2010 at 10:22
1 Answer 1
$('input:checkbox').click(function() {
if(this.id == '6' && this.checked)
$('input:checkbox:not(#6)').attr('checked', false);
else
$('#6').attr('checked', false);
});
answered May 17, 2010 at 10:00
ThiefMaster
320k85 gold badges608 silver badges648 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
ThiefMaster
Haha getting rep is a good motivation :P (Besides that, SO is a nice timesink during boring lectures. :D)
lang-js