![]() |
jQuery: check/uncheck all checkboxes with specific value - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: jQuery: check/uncheck all checkboxes with specific value (/showthread.php?tid=15672) |
jQuery: check/uncheck all checkboxes with specific value - El Forum - 02-11-2009 [eluser]codex[/eluser] Ok, I have this Code: onClick="$('input[@type=checkbox]').attr('checked', 'checked')" But how do you add a specific value? I'd like it to say 'check all checkboxes with value 5'. jQuery: check/uncheck all checkboxes with specific value - El Forum - 02-11-2009 [eluser]bitist[/eluser] Code: <script language="JavaScript" type="text/javascript" src="jquery.js"></script> This will toggle checkboxes which have value=5. jQuery: check/uncheck all checkboxes with specific value - El Forum - 02-11-2009 [eluser]codex[/eluser] Thanks! That does the trick. jQuery: check/uncheck all checkboxes with specific value - El Forum - 02-11-2009 [eluser]Nick Husher[/eluser] Note that the @property=value syntax has been depricated since jQuery 1.2. From the documentation: "Note: In jQuery 1.3 [@attr] style selectors were removed (they were previously deprecated in jQuery 1.2). Simply remove the '@' symbol from your selectors in order to make them work again." This is very similar, but lets you control what values you check and uncheck without rewriting your function: Code: jQuery(document).ready(function() { Your toggle button would look something like this: Code: <div class="toggle toggle-value-5 parent-class-checkbox-form">Toggle all "fives" in the "checkbox form"</div> |