Solved

How  do you toggle some text based on a click event

Posted on 2013-11-08
3
305 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
Comment Utility
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
Comment Utility
Are you looking for a function that hides/shows some text fields, depending on one or more conditions?
0
 

Author Closing Comment

by:smfmetro10
Comment Utility
Yep! Exactly! Thanks!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…

771 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