Help us understand the problem. What is going on with this article?

jqueryでのcheckboxの全選択

More than 5 years have passed since last update.

jquery1.10.1で checkboxを選択すると、他のチェックボックスを全選択させようとした。

そして無駄にハマったのでメモ

<input type="checkbox" id="check-all">
<input type="checkbox" value="1" name="a" class="bar">
<input type="checkbox" value="2" name="b" class="bar">
<input type="checkbox" value="3" name="c" class="bar">
$('#check-all').on('click', function() {
  $('input.bar:checkbox').attr('checked', $(this).is(':checked'));  
});
$('#check-all').on('click', function() {
  $('input.bar:checkbox').prop('checked', $(this).is(':checked'));  
});

誤のほうだと、2回目までは問題ないが、3回目からは、checked=checkedが付与されるのに
画面上はチェックが入らない現象になった。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away