question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Checkbox check-uncheck through attr and removeAttr doesnt work for second time.

See original GitHub issue

Description

<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

https://jsfiddle.net/jz5p57k9/

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dmethvincommented, Jul 21, 2016

Can you link to your test case that includes a native version, so we can see the difference?

0reactions
timmywilcommented, Jul 21, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found