Posted on October 5th, 2009
5669 views HTML: � � <input type="checkbox" id="all" /> Check/Uncheck all <div id="check"> <input type="checkbox" /> 1<br /> <input type="checkbox" /> 2<br /> <input type="checkbox" /> 3<br /> <input type="checkbox" /> 4<br /> <input type="checkbox" /> 5<br /> <input type="checkbox" /> 6<br /> <input type="checkbox" /> 7 </div> � � The function that does the magic is find(); this function finds all elements in our case input that has the type = checkbox. Then it sets the checked atribute to true. I used the toggle function for first (checks all) and second click (unchecks all) � � <script type="text/javascript" src="assets/jquery.js"></script> <script> $(document).ready(function() { $('#all').toggle( function() { $('#check').find('input[type=checkbox]').attr('checked', true); }, function() { $('#check').find('input[type=checkbox]').attr('checked', false); });��� }); </script> � |