I currently have an <a>
witin an <li>
which when clicked, opens a sub menu.
I now want to make it so that is you click that <a>
when it's parent has a class of .open
, it closes. But it won't fire.
The HTML:
<li class="menu-item-has-children open">
<a href="#">emerging market</a>
<ul class="sub-menu">
[sub menu stuff]
</ul>
</li>
So when you click .open a
, it should first hide
the sibling ul .sub-menu
and then removeClass
open
from the parent
The jQuery
jQuery(".open a").click(
function (){
console.log('here!'); // this never seems to fire
jQuery(this).sibling(".sub-menu").hide();
jQuery(this).parent().removeClass("open");
});
JS Fiddle showing the (working) opening function but the non-working closing function