Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

jquery toggle text

Posted on 2012-03-28
2
Medium Priority
?
828 Views
Last Modified: 2012-03-29
This script below works to toggle the div tag open and closed, but I want the text to also toggle and say "Show less" when it is clicked and show more when it is clicked again. When it is clicked once, the show less displays fine, but when it is clicked the second time to collapse the div, it still says show less and doesn't toggle back to "show more".
 <script>  
        $(document).ready(function(){
      $("p[id^='seeall']").click(function() {
         $(this).next("div").toggle();
      $(this).text(($('#seeall').text() == 'Show less') ? 'Show more' : 'Show less');
      });
      });
   </script>

html...
<p id="seeall#j#" style="text-decoration:underline;">Show more</p>
                                <div id="filter#j#" style="display:none;">
                                  text here
                               </div>
0
Comment
Question by:cbeverly
[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 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 37780697
$(document).ready(function() {
  $("p[id^='seeall']").click(function() {
    $(this).next("div").toggle();
    $(this).text(($(this).text() == 'Show less') ? 'Show more' : 'Show less');
  });
});
0
 

Author Closing Comment

by:cbeverly
ID: 37781542
Perfect! Thank you.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…

609 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