<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h2>A Nested List</h2>
<div id="mylist">
<ul>
<li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul>
</li>
<li>Milk</li>
</ul>
</div>
/* CSS */
ul li ul {
display: none; /* Hide the nested list first */
}
ul li.active ul {
display: block; /* Show the list when class 'active' is added to the li */
color: red;
}
// JavaScript
jQuery( "li:has(ul)" ).click(function(){ // When a li that has a ul is clicked ...
jQuery(this).toggleClass('active'); // then toggle (add/remove) the class 'active' on it.
});