Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Hide or show for different paragraphs

Posted on 2011-09-12
2
Medium Priority
?
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 59

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

721 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