?
Solved

hide and show

Posted on 2011-10-24
4
Medium Priority
?
188 Views
Last Modified: 2012-05-12
<div><a href="#">one</a>&nbsp; <a href="#">two</a>&nbsp; <a href="#">three</a></div>

<div> one content</div><div>two content</div><div> three content</div>

there are 3 links and 3 contents. how to hide and show contents based on click in jquery?
0
Comment
Question by:jcbmtt
  • 2
4 Comments
 
LVL 83

Accepted Solution

by:
leakim971 earned 1200 total points
ID: 37019800
test page : http://jsfiddle.net/Mt8Ep/

<div id="menu"><a href="#">one</a>&nbsp; <a href="#">two</a>&nbsp; <a href="#">three</a></div>
<div id="container">
    <div class="content"> one content</div><div class="content">two content</div><div class="content"> three content</div>
</div>

Open in new window

code :
$(document).ready(function() {
    $("a", "#menu").click(function(e) {
        e.preventDefault();
        $("div", "#container").hide();
        $("div:eq(" + $(this).index("a") + ")", "#container").show();
    })
})

Open in new window

0
 
LVL 4

Assisted Solution

by:CKY092
CKY092 earned 400 total points
ID: 37019817
0
 
LVL 34

Assisted Solution

by:Big Monty
Big Monty earned 400 total points
ID: 37019830
assuming you're using jQuery....

<script language='javascript'>
function showDiv( divNum ) {
    if( divNum == 1 ) {
        $('#div1').show();
        $('div2').hide();
        $('div3').hide();
    } elseif( divNum == 2 ) {
        $('#div2').show();
        $('div1').hide();
        $('div3').hide();
    } elseif( divNum == 3 ) {
        $('#div3').show();
        $('div1').hide();
        $('div2').hide();
    }
}
</script>

<div><a href="#" onclick='showDiv( 1 )">one</a>&nbsp; <a href="#" onclick='showDiv( 1 )">two</a>&nbsp; <a href="#" onclick='showDiv( 1 )">three</a></div>

<div id='div1'> one content</div><div id='div2'>two content</div><div id='div3'> three content</div>

0
 
LVL 34

Expert Comment

by:Big Monty
ID: 37019840
sorry, this line should be:

<div><a href="#" onclick='showDiv( 1 )">one</a>&nbsp; <a href="#" onclick='showDiv( 2 )">two</a>&nbsp; <a href="#" onclick='showDiv( 3 )">three</a></div>
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox 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…
Suggested Courses

807 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