hi i try to check/uncheck all checkboxes that don’t got a class to them. This is the code I got but it check the class boxes to.
$(document).ready(function() {
$('#ctl00_ContentPlaceHolder1_repReceivers_ctl00_chxAll').click(
function() {
if (!$("input[type='checkbox']").hasClass("testclass")) {
$("input[type='checkbox']").attr('checked', $('#ctl00_ContentPlaceHolder1_repReceivers_ctl00_chxAll').is(':checked'));
}});
});
any ideas where I go wrong?
EDIT
This suck but asp.net add a span around the checkbox input when given a cssclass, so the checkbox itself dont get the class. I tried to do like you say but like .not(thecheckboxid) but no luck.
EDIT CODE
<span class="testclass"><input id="ctl00_ContentPlaceHolder1_chxMale" type="checkbox" name="ctl00$ContentPlaceHolder1$chxMale" /></span>
You need to modify your code a bit, like this (updated for updated question):
Currently you’re checking if the first matched checkbox has the class, you want to filter out all those without the class from the batch you’re setting the
checkedproperty on. There are a few methods to do this, but:not()or.not()are the easiest here. The other change above is that since you’re inside an event handler for the_chxAllcheckbox, you can usethisinstead of repeating the ID, it’s shorter and faster 🙂 With this you can use the.checkedDOM property as well.