Solved

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

Posted on 2013-11-20
6
256 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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jquery auto complete 11 21
Jquery/JSON passing value from one function to another 12 60
jQuery for Each 12 35
jQuery Sticky Menu 24 36
I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
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 …
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…

820 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