Solved

Hide or show for different paragraphs

Posted on 2011-09-12
2
275 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 53

Expert Comment

by:Huseyin KAHRAMAN
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

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

734 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