Solved

How  do you toggle some text based on a click event

Posted on 2013-11-08
3
310 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
[X]
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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
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 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…

740 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