Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Hide or show for different paragraphs

Posted on 2011-09-12
2
Medium Priority
?
280 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 61

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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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 task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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

824 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