jquery - how is this.checked working in this code? -
how this.checked in code being calculated here? code working way should be, i'm not getting logic.
<p>select : <input type="checkbox" id="selectall"> </p> <p> item 1: <input type="checkbox" class="children" value="item1">item 2: <input type="checkbox" class="children" value="item2">item 3: <input type="checkbox" class="children" value="item3"> </p>
$(document).ready(function () { $('#selectall').click(function () { $('.children').prop('checked', this.checked); }); });
the this.checked
gives true or false used set checked
property of elements class children. if select selected this.checked give true
, false
otherwise.
to understand consider condition put on this.checked , set checked
property true
when checked , false
when not checked.
if(this.checked) $('.children').prop('checked', true); else $('.children').prop('checked', false);
or without condition
$('.children').prop('checked', this.checked);
Comments
Post a Comment