I've looked around the site and can't seem to find an answer for this question. Feel free to direct me to said question, if it does indeed exist.
I'm currently trying to do some tree-based checkbox operations, and I've come accross some behavior that I find strange.
In Google Chrome, I find that checking a checkbox leaves some "residue", if you will, that will not allow me to check or uncheck that checkbox using "attrRemove('checked');"
Interestingly enough, Internet Explorer (9) has the result I am going for. Please see this jsFiddle in both Chrome and IE for a good comparison of the effects.
http://jsfiddle.net/xixionia/9K5ft/
Can anyone explain these difference, and how I might be able to check / uncheck a checkbox in chrome which has been checked "by hand" ?
HTML
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
JavaScript
$(':checkbox').click(function(e) {
if($(this).is(':checked')) {
$(':checkbox').attr('checked', 'checked');
} else {
$(':checkbox').removeAttr('checked');
}
});
Thanks in advance for your help. :)
edit:
I was able to find this work around. If anyone else has any other solutions, please let me know, and I'll mark it as the solution. :)
$(':checkbox').click(function(e) {
var value = this.checked;
$(':checkbox').each(function(){ this.checked = value; });
});
edit:
Turns out, this problem is specific to jQuery 1.6. Previous versions of jQuery do not suffer from this issue. However, I have posted a solution here: Setting "checked" for a checkbox with jQuery?