In my page, i do have no.of checkboxes in the form. in that i am making checked some of them, i need to filter rest of the checkboxes and need to add separet event on those. i do like this:
var userLocales = $('input[type="checkbox"]', "form").filter(function(){
return $(this).val() === value["name"]
}).prop("checked",true);
$(userLocales).click(function(){
$(this).parent().toggleClass("red");
})
$('input:checkbox:not("checked")', "form").not(userLocales).click(function(){
$(this).parent().addClass("green"); //this is not working.. it works even for not selected elements..
})
But not working.. any correct way to get this done pelase..?
Answer: Use the jQuery prop() method You can use the jQuery prop() method to check or uncheck a checkbox dynamically such as on click of button or an hyperlink etc. The prop() method require jQuery 1.6 and above.
prop() and is() method are the two way by which we can check whether a checkbox is checked in jQuery or not.
By using jQuery function prop() you can dynamically add this attribute or if present we can change its value i.e. checked=true to make the checkbox checked and checked=false to mark the checkbox unchecked.
Clicking on the master checkbox selects all checkboxes; and unchecking it, deselects all checkboxes.
Given that you know how to get the checkboxes in the first place, consider:
checkboxes$.filter(':checked')....
or:
checkboxes$.filter(':not(:checked)')....
You need to use :checked
in the selector.
Try:
$('input:checkbox:not(":checked")', "form")
instead of
$('input:checkbox:not("checked")', "form")
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