Solved

Hide or show for different paragraphs

Posted on 2011-09-12
2
270 Views
Last Modified: 2012-05-12
Hello, I have two paragraphs. I want to click one to show, the other to hide. But if I click the hide part, all are hidden.
Jquery question.

Thanks for advice.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="../Users/hzhao/Downloads/jquery-1.6.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	$("#hide").click(function(){
		$("p").hide();
	});
	$("#show").click(function(){
		$("p").show();
	});
})
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<h2>This is a heading</h2>
<p id="show">This is a paragraph.</p>
<p id="hide">This is another paragraph.</p>

</body>
</html>

Open in new window

0
Comment
Question by:zhshqzyc
2 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 36523125
your request is logically impossible. do you want something like this?

p1 : show p2
p2 : hide p1

anyway, maybe you are looking for this

$("p").hide();
$("p").show();
-->
$("p hide").hide();
$("p show").show();
0
 
LVL 5

Accepted Solution

by:
DerZauberer earned 500 total points
ID: 36523192
You want them to toggle each other?

      $("#hide").click(function(){
            $("p#hide").hide();
            $("p#show").show();
      });
      $("#show").click(function(){
            $("p#hide").show();
            $("p#show").hide();
      });
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

707 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

17 Experts available now in Live!

Get 1:1 Help Now