Opened 10 years ago
Closed 10 years ago
#13716 closed bug (duplicate)
checkbox attr/removeAttr problems
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.9.0 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I believed the bug is involved with the version 1.9.0. Here is a simple example: <html>
<head>
<script src="./jquery-1.9.0.js" type="text/javascript"></script>
</head> <body>
<input id="test" type="button" value="click"> <fieldset>
<input class="test" type="checkbox" value="a"> <input class="test" type="checkbox" value="b"> <input class="test" type="checkbox" value="c"> <input class="test" type="checkbox" value="d"> <input class="test" type="checkbox" value="e">
</fieldset>
</body> <script>
$("#test").click(function(){
$(".test").each(function(){
if($(this).attr('checked'))
$(this).removeAttr('checked');
else
$(this).attr('checked', 'checked');
});
});
</script>
</html>
Here are the steps:
- Click the button, all the elements are checked.
- Click again, no checked.
- Click again, the attribute 'checked' is absolutely added, but the box is not checked.
The versions after 1.8.3 have the problem, but the version 1.8.3 is ok.
Duplicate of #13667.
Use
prop()
, notattr()
for this.