Solved

How do you make a collapsible div with "+" "-" that toggle

Posted on 2013-11-20
6
255 Views
Last Modified: 2013-11-21
Hi,

I have a collapsible div with some content that I need to have a "+" "-" next to the header "airplanes" that toggle as well.

Here is what I have so far

  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  
	    <script type="text/javascript">
	        $(function() {
	         $('#toggleair').click(function() {
	    $('.toggleair').toggle();
	    return false;
	});
        });
    </script>



<a href="#" id="toggleair">Airplanes</a><br /><br />
<div class="toggleair">
Cessna<br />
Piper<br />
Douglas</div>

Open in new window

0
Comment
Question by:smfmetro10
  • 3
  • 3
6 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39664591
http://jsfiddle.net/GaryC123/LWXdr/1/

CSS
#toggleair:after {
    content:" -";
}
.toggleair_expand:after {
    content:" +" !important;
}

Open in new window


jQuery
$(function() {
	$('#toggleair').click(function() {
$('#toggleair').toggleClass("toggleair_expand");
	    $('.toggleair').toggle();
	    return false;
	});
        });

Open in new window

0
 

Author Comment

by:smfmetro10
ID: 39666288
Thanks for the reply!

Is there a way for the "+" "-" to be on the other side of the "airplanes" and also to not have the underline (just have the underline under "airplanes")?

Thanks!
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39666369
This is based on this exact layout, it may need to be changed if you start changing the layout of your code
http://jsfiddle.net/GaryC123/LWXdr/3/
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:smfmetro10
ID: 39666371
and or be able to move the "+" "-" a couple spaces away from the  "airplanes" text?
0
 
LVL 58

Expert Comment

by:Gary
ID: 39666383
Did you miss my comment ^^^
0
 

Author Closing Comment

by:smfmetro10
ID: 39666465
Perfect! 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

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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 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)

821 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