Created
December 12, 2013 00:13
-
-
Save hsquareweb/7921027 to your computer and use it in GitHub Desktop.
Collapsable/Toggle Links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="collapse_list"> | |
<li><a href="#" data-toggle="collapse" data-target="#one">One</a></li> | |
<li><a href="#" data-toggle="collapse" data-target="#two">Two</a></li> | |
</ul> | |
<div class="collapse_content"> | |
<div id="one"> | |
<p>Content for div one</p> | |
</div> | |
<div id="two"> | |
<p>Content for div two</p> | |
</div> | |
</div><!-- end .collapse_content --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
$('a[data-toggle]').on("click", function(e) { | |
e.preventDefault(); | |
var target = $(this).attr("data-target"); | |
if( $(this).hasClass('active') ) { | |
$(this).removeClass('active'); | |
$('.collapse_content > div'+target).hide(); | |
} | |
else { | |
$(this).closest('ul.collapse_list').find('a[data-toggle]').removeClass('active'); | |
$(this).addClass('active'); | |
$('.collapse_content > div').hide(); | |
$('.collapse_content > div'+target).show(); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.collapse_content { | |
display: none; | |
} | |
.active { | |
background: #000; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can prob get rid of [data-toggle] and use [data-target] as a selector instead