Geeks With Blogs

News Google

Nick Harrison Blog<Nick>.Next()
I often will put stuff like report filters or control break groups inside fieldsets.

Its also nice to group related input fields.  This snippet will automatically wire up event handlers to allow you to show and hide the contents of the fieldset when the user clicks on the legend.

$(document).ready(function () {
    $('legend').click(function () {
        var $this = $(this);
        var parent = $this.parent();
        var contents = parent.contents().not(this);
        if (contents.length > 0) {
            $"contents", contents.remove());
        } else {

You can also easily collapse everything with this:

      $('#data legend').click();

This will collapse all of the fieldsets in the div tag with an id of data
Posted on Tuesday, January 15, 2013 4:04 PM jQuery | Back to top

Comments on this post: jQuery snippet to make fieldsets collapsible

comments powered by Disqus

Copyright © Nick Harrison | Powered by: