Wednesday 15 July 2015

javascript - How to checkall/uncheck all elements in a table which is inside form using JQuery -



javascript - How to checkall/uncheck all elements in a table which is inside form using JQuery -

hi trying figure out way in button changes value , checkboxes gets checked/unchecked on click of button.

i cannot understand how parse in dom. have tried on jsfiddle unable materialize it. can help me out in it.

here link.

here jquery code have written > $(document).ready(function(){ > $('.check:button').toggle(function(){ > alert('inside toggle function'); > $('input:checkbox').attr('checked',true); > $(this).val('uncheck all') > },function(){ > $('input:checkbox').removeattr('checked'); > $(this).val('check all'); > }) })

jsfiddle

jquery's toggle() functionality deprecated , removed time ago, @ to the lowest degree version of toggle() you're using.

you should listening change event, , utilize checked property toggle state of other checkboxes jquery's prop()

$('.selectall').on('change', function() { $('div input').prop('checked', this.checked); });

fiddle

i'm using on(), requires newer version of jquery 1 you're using in you're fiddle, should update latest version.

edit:

to button, need flag maintain track of state, , create you're own toggle

$('#selectall').on('click', function () { var flag = !$(this).data('flag'); $('#search_data input[type="checkbox"]').prop('checked', flag); $(this).data('flag', flag); });

fiddle

javascript jquery dom

No comments:

Post a Comment