jQuery how to toggle multiple panels (accordion?)

I'm trying to achieve what I thought would be something simple:

Category1          Category2             Category3

When I click on Category 1, it will expand its hidden panel to show optoins..

Category1          Category2             Category3
opt1
opt2

When I click on Category2 (or 3), Category1 closes and Category 2 opens.

Category1          Category2             Category3
                             option1
                             option2

Please help!
LVL 19
MontoyaProcess Improvement MgrAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nathan RileyFounderCommented:
Not styled exactly as you want, but here's the method.

https://jsfiddle.net/shunkLgs/

HTML:
<ul>
    <li id="cat1" style="display:inline;">Cat 1</li>
    
    
    <li id="cat2" style="display:inline;">Cat 2</li>
    
    
    <li id="cat3" style="display:inline;">Cat 3</li>
    
</ul>
<ul>
    <li id="cat1item" style="display:none;">hidden1</li>
    <li id="cat2item" style="display:none;">hidden2</li>
    <li id="cat3item" style="display:none;">hidden3</li>
</ul>

Open in new window


jQuery:
$( "#cat1" ).click(function() {
  $( "#cat1item" ).show("slow");
    $( "#cat2item" ).hide();
    $( "#cat3item" ).hide();
});

$( "#cat2" ).click(function() {
  $( "#cat2item" ).show("slow");
    $( "#cat1item" ).hide();
    $( "#cat3item" ).hide();
});

$( "#cat3" ).click(function() {
  $( "#cat3item" ).show("slow");
    $( "#cat1item" ).hide();
    $( "#cat2item" ).hide();
});

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eddie ShipmanAll-around developerCommented:
What you are looking fro, as far as I can see with the layout you have, is the Tab Panel.
https://jqueryui.com/tabs/
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.