Solved

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

Posted on 2009-04-02
3
415 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
Comment Utility
I believe this is what you want: http://jqueryui.com/demos/accordion/
0
 

Author Closing Comment

by:ron4721
Comment Utility
Thanks asianandrew!  Exactly what i was searching for!
0
 
LVL 5

Expert Comment

by:prokvk
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now