Solved

jquery toggle text

Posted on 2012-03-28
2
817 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
2 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now