Using jQuery with HTML Text Links to Show/Hide Multiple DIVs -


i'm creating menu page local restaurant. @ top of page of text based links each portion of menu such as:

appetizers | soups , salads | entrees

the html markup these is:

<a id="show_apps">appetizers</a> | <a id="show_soups">soups , salads</a> | <a id="show_entrees">entrees</a> 

my css setup this:

#menu_container{   width: 650px;   height: auto;   padding-left: 30px; }  #menu_container div{display:none;} 

and menu sections setup this

<div id="menu_container">   <div id="menu_apps">     content of app section here   </div>   <div id="menu_soups">     content of soups section here   </div>   <div id="menu_entrees">     content of entrees section here   </div> </div> 

what trying find solution when clicks on link each section show div if click on section, replace viewed div next one. example: user clicks on "appetizers" , div loads clicks on "soups , salads" , "appetizers" div closed , "soups" div shown, multiple divs aren't visible @ once. have been toying around show(), hide(), , toggle() can't figure out how end result of clicking on other links re-hide , show targeted div. hope makes sense.

tia insight!

check out jsfiddle

<div id='nav'>     <a id="show_apps">appetizers</a> | <a id="show_soups">soups , salads</a> | <a id="show_entrees">entrees</a> </div>   $(document).ready(function(){    $("#nav a").click(function(){       var id =  $(this).attr('id');       id = id.split('_');       $("#menu_container div").hide();        $("#menu_container #menu_"+id[1]).show();    }); }); 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

python 3.x - PyQt5 - Signal : pyqtSignal no method connect -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)