Solved

How  do you toggle some text based on a click event

Posted on 2013-11-08
3
307 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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 how to dynamically set the form action using jQuery.
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…

786 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