Jquery:  Showing and Hiding DIVs when a hyperlink is clicked

Posted on 2008-10-21
Medium Priority
Last Modified: 2010-04-21
I am hoping to use JQuery to do the following:

1. Hide all DIVs on a page with the class "content".
2. When a link with the class "mylinks" is clicked, the DIV with the matching ID should be shown and any other visible DIVs should be hidden.

For example, if the user clicked on the "option 2" link, the "option2" div should be made visible and any other divs with the class "content" should be hidden.

The idea is to use the links as a toggle for what to display in a particular section of the page.  It seems like this should be easy in Jquery but all of the examples I've run across have be more confused.

Any help with be appreciated!
<a href = "#" class = "mylinks" id = "option1">Click here for option 1</a>
<a href = "#" class = "mylinks" id = "option2">Click here for option 2</a>
<a href = "#" class = "mylinks" id = "option3">Click here for option 3</a>
<div id = "option1" class = "content">
Option 1 content goes here
<div id = "option2" class = "content">
Option 2 content goes here
<div id = "option3" class = "content">
Option 1 content goes here

Open in new window

Question by:OaktownBill
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
LVL 16

Accepted Solution

sh0e earned 2000 total points
ID: 22773076
  $('#' + this.id).show();

Author Comment

ID: 22773165
Awesome.  Thanks for your help!

Author Closing Comment

ID: 31508593
Thanks for your help!

Featured Post

Industry Leaders: 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

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

770 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