I’ve got a jQuery selector thats not working desipte my best efforts to fix it. Any advice?
$(':checkbox:(not(:checked))[name=this.name][value="Done"]').attr({
checked: 'checked',
disabled: 'disabled'
});
It should check and disable a checkbox if it’s not already checked, has a name attribute = this.name and a value of Done.
I’ve been fiddling around with it http://jsfiddle.net/PottyMonster/s8RMJ/ I dunno if that’ll work though.
This should do it:
Updated example: http://jsfiddle.net/s8RMJ/22/
You need to concatenate the value of
this.nameinto the selector.I also added
inputto the selector to make it faster.Also, you had an extra
()around the:not()so it looked like:(not())which isn’t valid.EDIT:
Just wanted to note that I had replaced the
:checkboxselector with[type=checkbox]in order to make your selector valid forquerySelectorAll.Now it will get a big performance boost in browsers that support
qsa.