Solved

jQuery -- links -- on click show one div/hide the rest

Posted on 2009-04-02
3
423 Views
Last Modified: 2012-08-13
Hi,
  Is there an available jQuery script where i can have 4 links.  When the user clicks on one of them, it shows a hidden div below the link (the div would have a photo and text).  When the user clicks on a different link, it shows the hidden div for this different link, AND hides all other divs, etc...
Thanks,
-Ron.
0
Comment
Question by:ron4721
3 Comments
 
LVL 3

Accepted Solution

by:
asianandrew earned 500 total points
ID: 24053585
I believe this is what you want: http://jqueryui.com/demos/accordion/
0
 

Author Closing Comment

by:ron4721
ID: 31565956
Thanks asianandrew!  Exactly what i was searching for!
0
 
LVL 5

Expert Comment

by:prokvk
ID: 24053712
Try this:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
<head>
    <title>Page title</title>
    
    <script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>
    
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    
    <script type="text/javascript">
        $(function () {
            $('a').click(function () {
                $('div.desc').hide();
            
                $(this).next('div.desc').show();
                
                return false;
            });
        });
    </script>
</head>
 
<body>
 
    <a href="">Link 1</a>
    <div class="desc" style="display: none;">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent risus dui, dictum vel, pellentesque a, pharetra sagittis, risus. Praesent feugiat sollicitudin erat. Curabitur sollicitudin. Nam ultricies. Etiam iaculis dapibus ligula. Integer accumsan diam id elit. Cras luctus. Duis lacus erat, egestas 
    </div>
    
    <br />
    
    <a href="">Link 2</a>
    <div class="desc" style="display: none;">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent risus dui, dictum vel, pellentesque a, pharetra sagittis, risus. Praesent feugiat sollicitudin erat. Curabitur sollicitudin. Nam ultricies. Etiam iaculis dapibus ligula. Integer accumsan diam id elit. Cras luctus. Duis lacus erat, egestas 
    </div>
    
    <br />
    
    <a href="">Link 3</a>
    <div class="desc" style="display: none;">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent risus dui, dictum vel, pellentesque a, pharetra sagittis, risus. Praesent feugiat sollicitudin erat. Curabitur sollicitudin. Nam ultricies. Etiam iaculis dapibus ligula. Integer accumsan diam id elit. Cras luctus. Duis lacus erat, egestas 
    </div>
    
    <br />
    
    <a href="">Link 4</a>
    <div class="desc" style="display: none;">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent risus dui, dictum vel, pellentesque a, pharetra sagittis, risus. Praesent feugiat sollicitudin erat. Curabitur sollicitudin. Nam ultricies. Etiam iaculis dapibus ligula. Integer accumsan diam id elit. Cras luctus. Duis lacus erat, egestas 
    </div>
    
</body>
</html>

Open in new window

0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

820 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