Solved

How  do you toggle some text based on a click event

Posted on 2013-11-08
3
306 Views
Last Modified: 2013-11-10
Hi Experts!

Thanks to GaryC123 I am almost done with this project.  I just need to toggle between some text based on a click.

I have a loop that finds some information. If there is more than one record it creates a collapsible div that you can toggle to see the additional info.

I just need to be able to toggle between a "more" and "hide".

Right now if you click one div than all the other div's will change text as well. (however, they dont toggle so that's a start)

Also there is a "show/hide all" button that has to toggle the individual div's text as well .

Here is what I have so far:

<script type="text/javascript">
$(function() {
  $('div.moredates').hide();
  $('a.moredatesclick').click(function() {
    // find the next element after the one clicked and slideToggle it
    $(this).next().slideToggle();
    //$(this).hide();  // "more" stays visible 
    
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){
    $(".moredatesclick").click(function(){
        $('#visible').slideToggle();            
        $('.moredatesclick').html($('.moredatesclick').text() == 'Hide me' ? 'Show Me' : 'Hide me');
    });
})
</script>

                                  <a class="moredatesclick">more</a>
                                 <div class="moredates" data-collapsed="true">  </div>

Open in new window

0
Comment
Question by:smfmetro10
3 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39635073
Not sure I am following you...something like this
http://jsfiddle.net/cegqK/1/

$(function() {
  $('div.moredates').hide();

});
$(document).ready(function(){
    $(".moredatesclick").click(function(){
        $(this).next().slideToggle();            
        $(this).html($(this).text() == 'Hide me' ? 'Show Me' : 'Hide me');
    });
})

Open in new window

0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39635769
Are you looking for a function that hides/shows some text fields, depending on one or more conditions?
0
 

Author Closing Comment

by:smfmetro10
ID: 39637364
Yep! Exactly! Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
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…

896 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

13 Experts available now in Live!

Get 1:1 Help Now