expand/collapse table rows with JQuery

后端 未结 7 991
闹比i
闹比i 2020-11-27 11:09

I want to expand and collapse table rows when header columns is clicked. I only want to expand/collapse rows which are under the specific header (clicked).

Here is m

7条回答
  •  清歌不尽
    2020-11-27 11:22

    I would say using the data- attribute to match the headers with the elements inside it. Fiddle : http://jsfiddle.net/GbRAZ/1/

    A preview of the HTML alteration :

       
        Header
       
       
         data
         data
       
       
         data
         data
       
    

    JS code :

    $(".header").click(function () {
       $("[data-for="+this.id+"]").slideToggle("slow");
    });
    

    EDIT: But, it involves some HTML changes. so I dunno if thats what you wanted. A better way to structure this would be using or by changing the entire html to use ul, ol, etc or even a div > span setup.

提交回复
热议问题