Solved

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

Posted on 2013-11-08
2
452 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
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)

762 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

22 Experts available now in Live!

Get 1:1 Help Now