I have the following portion of code.
I'd like to hide sub-menu
originally and display if the link Type
is clicked. How do I do this?
<div class="thirdy">
<ul class="sf-menu" style="list-style-type:none">
<li class="main"><a href="#">Type</a>
<ul class="sub-menu">
<li><a href="/teams/" title="View all Teams" >Teams</a></li>
<li><a href="/events/" title="View all Events" >Event</a></li>
</ul>
</li>
</ul>
</div>
You can write a click event on a element and toggle its next sibling in click handler:
$('.main a').click(function(){
$(this).next().toggle()
}).click();//<-- for hiding the options by default on load
you code be something like this http://jsfiddle.net/elviz/045z9gdr/1/
$(".sub-menu").toggle();
$(".main").click(function(){
$(".sub-menu").toggle();
});
You can use toggleClass()
Jquery
$(".main").click(function(){
$(this).find($(".sub-menu")).toggleClass("hidden");
});
CSS
.hidden{
display: none;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.