checkbox - Jquery toggling multiple block of checkboxes -
i have working, there slight issue...
i have 2 blocks of 3 checkboxes. grouping , grouping b
if select 'all' grouping of checkboxes state in grouping toggled.
if select 'all' grouping b have click twice grouping b checkboxes state change.
this jquery i'm using:
var checked = false; $('.all').click(function () { e = $(this).attr('name'); checked = !checked; $('input[class=' + e ).prop('checked', checked); });
i've created fiddle illustration http://jsfiddle.net/1kgneajl/
why have click twice grouping b ? plan add together farther groups need ensure isn't going worse. happen if have 10 groups ?
any way resolve ?
thanks
because of this:
var checked = false;
both groups using same variable... when set grouping false, when click @ grouping b , it'll false well.. boxes checked in grouping b
a quickfix stores grouping check in grouping context :
$('.all').click(function () { e = $(this).attr('name'); checked = $(this).attr('checked'); checked = !checked; $(this).attr('checked', checked); $('input[class=' + e + ']').prop('checked', checked); });
no need of checked
variable anymore
jquery checkbox toggle
No comments:
Post a Comment