I am trying to make a menu that slides down sub menu items (+changes background color) when clicked on. When a different menu item is clicked on, the other open should close (sub menu item slide back). I am using the html code below, (I am hiding the sub1 and sub2 by using dispay:none;)
Please view the code http://jsfiddle.net/kxvKA/
At the moment all slides open together, I want one to open at a time, and when the other is clicked on. the first should close
<ul class="nav">
<li class="mainnav">MAINNAV</li>
<li class="sub1">SUB1</li>
<li class="sub2">SUB2</li>
</ul>
<ul class="nav">
<li class="mainnav">MAINNAV2</li>
<li class="sub1">SUB1</li>
<li class="sub2">SUB2</li>
</ul>
and JQuery code
$(".mainnav").on("click", function(){
$(".sub1, .sub2").slideDown("fast");
$( ".mainnav" ).animate({
backgroundColor: "#3A3A3A",
}, 500 );
});