Geeks With Blogs

@neh123us
  • neh123us T4 sould be your outsourcing strategy https://t.co/1ZceCUKWKE T4 - The Insource Code Monkey about 447 days ago
  • neh123us Had a need for Dynamic Views in MVC today. Wanted to use a Partial view on two different views with different ViewModels about 495 days ago

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) {
            $this.data("contents", contents.remove());
        } else {
            $this.data("contents").appendTo(parent);
        }
    });
 });


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: GeeksWithBlogs.net | Join free