I want to be able to toggle the visibility of my submenus when a link is clicked. Here's an example code snippet:
<ul>
<li><a href="www.example.com">Test</a></li>
<li><a href="www.example.com">Test</a></li>
<li class="submenu">
<a href="#">Test 2</a>
<ul class="ul_submenu">
<li><a href="www.example.com">Test</a></li>
<li><a href="www.example.com">Test</a></li>
<li class="submenu_2">
<a href="#">Test 3</a>
<ul class="ul_submenu_2">
<li><a href="www.example.com">Test</a></li>
</ul>
</li>
</ul>
</li>
</ul>
$( 'li.submenu a[href="#"]').click(function(e) {
e.preventDefault();
$("ul.ul_submenu").toggle();
});
You can view a working example on JSFiddle.
I need the ability to click on a link even if it has child elements, and change the display of the list item. However, I also want to prevent the page from reloading when a link like this is clicked: <a href="#"></a>