Using jQuery fadeToggle for the navigation bar, how to show / hide content one a...

 2 years ago
source link: https://www.codesd.com/item/using-jquery-fadetoggle-for-the-navigation-bar-how-to-show-hide-content-one-at-a-time.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Using jQuery fadeToggle for the navigation bar, how to show / hide content one at a time?


I am very new to CSS/Jquery so please forgive the assumed simplicity of this question.

I have a navigation links to: ABOUT and CONTACT. I have figured out how to fadeToggle their content. However, if you click one link followed by a different one, their content fades in/out sequentially and stack on top of each other. I would like for the content of each link to automatically fade out if a different link is clicked on. For example, if the user clicks "CONTACT", the contact information will fade in. Then, if the user clicks "ABOUT" I would like for the contact information to fade out and the about information to fade in. Can anyone help in lay language?

What I have so far in HTML/CSS/JS:


<div id="navbar">
<li><a href="#" id="about">ABOUT</a></li>
<li><a href="#" id="contact">CONTACT</a></li>

<div id="aboutcontent" class="hidden">
 <p> ABOUT ME </p>

<div id="contactcontent" class="hidden">



.hidden {display:none}
#navbar ul li { display: inline;}


$('a#contact').click(function() {
return false;

$('a#about').click(function() {
return false;  


Try this code instead:


  $('a#contact').click(function(e) {

  $('a#about').click(function(e) {


You can see a working example here: http://jsfiddle.net/ECBhr/1/

About Joyk

Aggregate valuable and interesting links.
Joyk means Joy of geeK