#9210 closed bug (duplicate)
jquery can't check checkboxes after manual checks
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | 1.6.1 |
Component: | attributes | Version: | 1.6 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Code like
$('#checkbox').attr('checked', true);
doesn't work when the target checkbox has been manually checked/unchecked. This is not an issue with jquery 1.5.2 but has appeared in 1.6. The bug exists in (at least) firefox 3.6.17 and Chromium 11.0.696.57, both running on ubuntu 10.10.
A complete example is as follows. First try to click on "check both" and see that both the other checkboxes are checked and unchecked. Then click on "check me" and click on "check both" again. Notice than "check me" aren't checked this time.
<html> <head> <title>Check the checked checkboxes</title> <script src="jquery-1.6.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function() { $('#check_both').change(function() { $('#checkme1').attr('checked', $(this).is(':checked')); $('#checkme2').attr('checked', $(this).is(':checked')); }); }); </script> </head> <body> <p> <input id="check_both" name="check_both" type="checkbox"/> <label for="check_both">Check both</label> </p> <p> <input id="checkme1" name="checkme1" type="checkbox"/> <label for="checkme1">Check me</label> </p> <p> <input id="checkme2" name="checkme2" type="checkbox"/> <label for="checkme2">Check me as well</label </p> </body> </html>
Change History (5)
comment:1 Changed 12 years ago by
comment:2 Changed 12 years ago by
Component: | unfiled → attributes |
---|---|
Milestone: | 1.next → 1.6.1 |
Priority: | undecided → low |
Resolution: | → duplicate |
Status: | new → closed |
comment:4 Changed 10 years ago by
Well, even if it was originally to forget, Thanks [email protected] : It gave me an hint to solve a problem I had with a version of CheckboxTree plugin: http://code.google.com/p/checkboxtree/
The problem was that it was coded using .live() and .attr() functions. It was still working (jQuery 1.9.1) when using jquery-migrate-1.0.1
When I replaced all .live statements with .on(), the behaviour of .attr() was modified. My knowledge of jquery changelog is unsufficient to find why it occurs but I needed to replace attr() statements by prop() ones and the widget is fully functional again.
Thanks again
Never mind ... didn't see the other tickets about the issue, until after I submitted (the instructions was hidden among the 'are you at the right place' stuff). The solution is (of course) to use .prop() instead of .attr(). Feel free to close the issue if you have the appropriate rights.