Skip to content

Instantly share code, notes, and snippets.

@ituki
Created July 10, 2013 07:59
Show Gist options
  • Save ituki/5964303 to your computer and use it in GitHub Desktop.
Save ituki/5964303 to your computer and use it in GitHub Desktop.
jQueryで全選択・全解除はprop使う ref: http://qiita.com/ituki_b/items/17eab8c38a2ad5392660
<div class="allCheck">
<input type="checkbox" id="allCheck01"><label for="allCheck01">全選択・全解除</label>
</div>
<div>
<input type="checkbox" id="check01"><label for="check01">アイテム01</label>
<input type="checkbox" id="check02"><label for="check02">アイテム02</label>
<input type="checkbox" id="check03"><label for="check03">アイテム03</label>
</div>
$('.allCheck input,.allCheck label').click(function(){ //全選択・全解除をクリックしたとき
var items = $(this).closest('.allCheck').next().find('input');
if($(this).is(':checked')) { //全選択・全解除がcheckedだったら
$(items).prop('checked', true); //アイテムを全部checkedにする
} else { //全選択・全解除がcheckedじゃなかったら
$(items).prop('checked', false); //アイテムを全部checkedはずす
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment