check all jquery not working for dynamically populated checkbox -


i have jquery function select checkboxes , populated in php loop. output of loop similar below:

<label class="check"><input type="checkbox" name="selectall" value="all"/> select all</label> <label class="col-md-3 col-xs-12 control-label">types of function</label> <div class="col-md-6 col-xs-12">                                                                                                 <div class="col-md-7">                                             <label class="check"><input type="checkbox"  name="chkuser" class="icheckbox"/> birthday</label>     </div>     <div class="col-md-7">                                             <label class="check"><input type="checkbox"  name="chkuser" class="icheckbox"/> family function</label>                        </div>     <div class="col-md-7">                                             <label class="check"><input type="checkbox"  name="chkuser" class="icheckbox"/> conference</label>                             </div>     <div class="col-md-7">                                             <label class="check"><input type="checkbox"  name="chkuser" class="icheckbox"/> wedding</label>                                </div>     <div class="col-md-7">                                             <label class="check"><input type="checkbox"  name="chkuser" class="icheckbox"/> corporate</label>                                  </div> </div> 

and jquery function :

$('.selectall').click(function() { //alert('hhh');     if ($(this).is(':checked')) {         $('.icheckbox').attr('checked', 'checked');     } else {         $('.icheckbox').attr('checked', false);     } }); 

but unfortunately not working ! what's wrong ?

jsfiddle here

use prop() setting checked , unchecked

  $('[name=selectall]').change(function() {            $('.icheckbox').prop('checked', this.checked);     }); 

note: there no selectall class in html

prop demo

attr domo working once


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -