jquery toggle text

Posted on 2012-03-28
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".
      $("p[id^='seeall']").click(function() {
      $(this).text(($('#seeall').text() == 'Show less') ? 'Show more' : 'Show less');

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

Accepted Solution

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

Author Closing Comment

ID: 37781542
Perfect! Thank you.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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 64
How do I add counter to html listbox using jquery 2 44
javascript works in Chrome, but none of the other browsers 14 54
Check if field exists SPUtility 5 47
In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…
Suggested Courses

732 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