javascript - How to hide one section of the page and show the other section when a heading is clicked? jQuery -


i made example in jsfiddle: http://jsfiddle.net/yt88bsnf/1/

one section has display of none, , other shown. trying accomplish when 1 of h2 element clicked, section below becomes shown (unless shown, stay shown), , other h2 element display changes none (unless has display of none).

any or suggestions appreciated! thanks

html:

<div id="container">     <h2>section one</h2>     <h2>section two</h2> </div>  <div id="section_one">     section 1 </div>  <div id="section_two">     section 2 </div> 

css:

#container{     overflow:hidden; }  #container h2{     float:left;     margin-right:30px;     cursor:pointer; }  #section_two{     display:none; } 

check fiddle

you can use jquery show() , hide(). more information see w3scools

and docs see here

js

$("#header1").click(function () {      $("#section_one").show();     $("#section_two").hide(); }); $("#header2").click(function () {      $("#section_two").show();     $("#section_one").hide();  }); 

html

<div id="container">      <h2 id="header1">section one</h2>       <h2 id="header2">section two</h2>  </div> <div id="section_one">this section one</div> <div id="section_two">this section two</div> 

i've added each h2 id (header1 , header2) , used id show , hide divs respectively..please try it..


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -