Solved

changing text dynamically

Posted on 2011-09-21
2
138 Views
Last Modified: 2012-05-12
i have 2 links that hides and shows content based on click.
show should become hide when div is open and vice versa.

<html>
<head></head>
<body>
<a href="#"><span>show</span> what are the conditions </a>
<div style="display:none"> MS, MD </a>
<a href="#"><span>show</span> what is the age limit </a>
<div style="display:none"> 32 </a>
</body>
</html>
0
Comment
Question by:jcbmtt
[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
2 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36577564
Test page : http://jsfiddle.net/A4ups/
$("a").click(function(e) {
    e.preventDefault();
    if( $("span",this).text() == "show" ) {
        $(this).next("div").show();
        $("span",this).text("hide");
    }
    else {
        $(this).next("div").hide();
        $("span",this).text("show");
    } 

})

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36577568
better with a class : http://jsfiddle.net/A4ups/1/


<a href="#" class="sh"><span>show</span> what are the conditions </a>
<div style="display:none"> MS, MD </a>

<a href="#" class="sh"><span>show</span> what is the age limit </a>
<div style="display:none"> 32 </a>

Open in new window

$("a.sh").click(function(e) {
    e.preventDefault();
    if( $("span",this).text() == "show" ) {
        $(this).next("div").show();
        $("span",this).text("hide");
    }
    else {
        $(this).next("div").hide();
        $("span",this).text("show");
    } 

})

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Jquery form 9 62
Set a parameter in a properties file and use in html table. 14 53
Why does my submit button remain disabled 3 31
Woo-commerce gallery not working properly 12 35
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
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

738 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