Checkbox check-uncheck through attr and removeAttr doesnt work for second time.
See original GitHub issueDescription
<div id="container">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
</div>
<button type="button" id="addAll">add all</button>
<button type="button" id="removeAll">remove all</button>
$("#addAll").click(function() {
$("#container input:checkbox").attr('checked', 'checked');
});
$("#removeAll").click(function() {
$("#container input:checkbox").removeAttr('checked');
});
Running above code, for the checking unchecking second time nothing happens. Even though attributes are added and removed normally. Using native setAttribute and removeAttribute works fine.
Link to test case
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
prop('checked',false) or .removeAttr('checked')? - Stack Overflow
If your goal is to uncheck the checkbox, you really do want to affect the property, not the attribute, and there's no need...
Read more >How to check and uncheck a checkbox with jQuery
Today's post looks at how to tell if an HTML form checkbox is checked or not checked with jQuery and then how to...
Read more >Why the checkbox stops showing the real value after clicking it ...
I don't know why this happens at all, but, I've found a way to solve it: $("#cbTempsPare").change(function(){ if (this.checked) { var ...
Read more >jQuery set checkbox checked - Stack Overflow
I can check/uncheck using code if the check box is in the page, but is it's in ... op: "edit" }, }).done(function (data)...
Read more >What is the simplest way to uncheck a checkbox with jQuery?
I use .attr("checked", true) and .attr("checked", false) . It's elegant and has worked in all my tests so far. 91. 91.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Can you link to your test case that includes a native version, so we can see the difference?
In 2.1.4, we were still setting the
checked
IDL along with the attribute, for back-compat. Makes sense that 3.0+ works as expected.