[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Trying to get jquery style accordian effect to work inside an html table

Posted on 2013-06-06
4
Medium Priority
?
801 Views
Last Modified: 2013-06-10
I'm trying to get the jquery style accordian option to work inside an html table.  I have 2 header rows that won't change and then I have a dynamic html table that gets built. I have included some html code and javascript code I have as an example:

This is the output example
I would like to be able to hide/show first 2 rows after 'This is the header' is clicked and show/hide 3 rows after 'This is another header' is clicked

Main Header                              // static first header
header 1      header 2      header 3    // static second header
This is the header                      // first accordian header              
Research      Description      Partner
Research      Description      Partner
This is the another header         // second accordian header
Research_2      Description_2      Partner_2
Research_2      Description_2      Partner_2
Research_2      Description_2      Partner_2

<table class="research">
    <tbody>
        
        <tr><td colspan="3">Main Header</td></tr>
        <tr><td>header 1</td><td>header 2</td><td>header 3</td></tr>               
        
        <tr class="accordion">
            <td colspan="3">This is the header</td>
        </tr>
        <tr>
            <td>Research</td>
            <td>Description</td>
            <td>Partner</td>
        </tr>
        <tr>
            <td>Research</td>
            <td>Description</td>
            <td>Partner</td>
        </tr>  
        
        
        <tr class="accordion">
            <td colspan="3">This is another header</td>
        </tr>
        <tr>
            <td>Research_2</td>
            <td>Description_2</td>
            <td>Partner_2</td>
        </tr>
        <tr>
            <td>Research_2</td>
            <td>Description_2</td>
            <td>Partner_2</td>
        </tr>        
        <tr>
            <td>Research_2</td>
            <td>Description_2</td>
            <td>Partner_2</td>
        </tr>        

    </tbody>
</table>

$(function() {
    var $research = $('.research');
    $research.find("tr").not('.accordion').hide();
    $research.find("tr").eq(0).show();
    
    $research.find(".accordion").click(function(){
        $(this).siblings("tr").fadeToggle(500);
    }).eq(0).trigger('click');
});

Open in new window

0
Comment
Question by:dmalovich
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
Mrunal earned 2000 total points
ID: 39228117
Here is your solution:

http://jsfiddle.net/PCpe4/
0
 

Author Closing Comment

by:dmalovich
ID: 39229019
Perfect. Thanks....
0
 

Author Comment

by:dmalovich
ID: 39229212
Is there any way to default the tabs to close when the page opens and have the user choose to open up a tab.  Sorry for asking after I closed the question.....
0
 
LVL 22

Expert Comment

by:Mrunal
ID: 39233978
Yes this is possible:

just add below line in document.ready event

$('#table1 tr.accordion:eq(1)').nextUntil('tr.accordion').hide();

This will hide second content panel on page load.
you can change this index from 1 to 0 (zero).

Hope this helps you.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question