Solved

How do you make a collapsible div with "more" "less" that toggle

Posted on 2013-11-08
2
453 Views
Last Modified: 2013-11-08
Hi,

I am looking for a way to loop through a recordset and if It has more than one record append a  "more" "less" with a collapsible div that holds the extra info.

I can "hard code" it but I need a way to have it be dynamic... I'm guess its using the .next method.

Thanks!
0
Comment
Question by:smfmetro10
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39634678
Something like this
http://jsfiddle.net/GaryC123/Ua9q9/1/

<div class="parent more">Header
    <div>sub text</div>
</div>

Open in new window

.parent div {
    display:none
}
.showmore:after {
    content:"+"
}
.showless:after {
    content:"-"
}

Open in new window

$(".more").each(function(){
    $(this).addClass("showmore")
})
$(".more").click(function(){
    if($(this).hasClass("showless")){
        $(this).removeClass("showless").addClass("showmore")}
    else{
        $(this).addClass("showless").removeClass("showmore")
    }
  $("div",this).slideToggle()
})

Open in new window

0
 

Author Closing Comment

by:smfmetro10
ID: 39634935
Yep! 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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

863 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

24 Experts available now in Live!

Get 1:1 Help Now