Saturday, November 14, 2009

Using jQuery Selectors to Select all/Select none in checkboxes

jQuery is fun! Using jQuery Selectors you can select page elements in all sorts of ways - in this example to select/unselect all checkboxes where name starts with 'chk-' (formatted 'chk-{id}'):

<a href="#" title="Select all" onclick=
"$('input[name^=chk-]').attr('checked', 'checked')">
<a href="#" title="Select none" onclick=

<input id="chk-200" name="chk-200" type="checkbox" />
<input id="chk-201" name="chk-201" type="checkbox" />
Gotta love jQuery!

No comments:

Post a Comment