javascript - Gmail like Checkbox functionality -
i want implement gmail checkbox functionality: in if checkall checkbox clicked, listed checkbox selected/unselected, if listed checkbox selected, checkall checkbox checked. , if checkbox checked, - sign checkbox appear.
i have implement logic using div. here logic: html:
<table id="viewtable" class="tableeffectfull"> <thead> <tr> <th class="selectcol"><div class="uncheckedcheckboxall"></div></th> <th class="noscol">products</th> </tr> </thead> <tr> <td><div class="uncheckedcheckbox"></div></td> <td>abcd</td> </tr> <tr> <td><div class="uncheckedcheckbox"></div></td> <td>pqrs</td> </tr> </table>
css:
.uncheckedcheckbox{ width: 25px; height: 25px; margin-top: -4px; background: transparent url(images/prettycheckable-green.png) top left no-repeat; } .checkedcheckbox{ background: transparent url(images/prettycheckable-green.png) 0 -60px; } .uncheckedcheckboxall{ width: 25px; height: 25px; margin-top: -4px; background: transparent url(images/checkable-green.png) top left no-repeat; } .checkedcheckboxall{ background: transparent url(images/checkable-green.png) 0 -60px; }
script: //updated scripts:
$(".uncheckedcheckbox").click(function () { $(this).toggleclass('checkedcheckbox'); $('.uncheckedcheckboxall').toggleclass('checkedcheckboxall', $('.checkedcheckbox').length == $(".uncheckedcheckbox").length) }); $(".uncheckedcheckboxall").click(function () { $(this).toggleclass('checkedcheckboxall'); $('.uncheckedcheckbox').toggleclass('checkedcheckbox') });
now problem not getting if listed checkbox selected, make checkedall checkbox checked , if checked highlighted checkbox display in checkedall.
below image using:
try
i have changed script :
$(".uncheckedcheckbox").click(function () { $(this).toggleclass('checkedcheckbox'); if ($('.checkedcheckbox').length == 2) { $('.checkboxall').addclass('checkedcheckboxall').removeclass('minuscheckboxall') } else { $('.checkboxall').removeclass('checkedcheckboxall') if ($('.checkedcheckbox').length == 0) $('.checkboxall').removeclass('minuscheckboxall') else $('.checkboxall').addclass('minuscheckboxall') } }); $(".checkboxall").click(function () { $(this).removeclass('minuscheckboxall') $(this).toggleclass('checkedcheckboxall'); $('.uncheckedcheckbox').toggleclass('checkedcheckbox', $(this).is('.checkedcheckboxall')) });
added 2 new css classes too...
.uncheckedcheckbox { width: 25px; height: 25px; margin-top: -4px; background: red top left no-repeat; } .checkedcheckbox { background: pink 0 -60px; } .checkboxall { background: white; } .uncheckedcheckboxall { width: 25px; height: 25px; margin-top: -4px; background: blue top left no-repeat; } .checkedcheckboxall { background: black 0 -60px; } .minuscheckboxall { background: green 0 -60px; }
Comments
Post a Comment