Kind of a funny problem here.
I want to check the checkbox when the parent div is checked, but it is DESELECTING the checkbox when the CHECKBOX is clicked on ;)
It works fine when the name is clicked on. How do i solve this?
//layout
<div class="parent">
<input type="checkbox"/> <a>Name</a>
</div>
//check the box when parent div is clicked
$(".parent").click(function(event){
event.preventDefault();
checkbox=$(this).find("input:checkbox");
checkbox.attr("checked","checked");
});
Try this.
<div class="parent">
<input type="checkbox" class="check"/> <a>Name</a>
</div>
$(".parent").click(function(event){
$(".check:not(:checked)").attr('checked','checked');
});
$(".check").click(function(event){
event.stopPropagation();
});
jsFiddle is here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With