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);     }); }); 

jsfiddle

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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -