<li class="menu-229 menuparent menu-path-front even">
<a title="About" href="/tca/">about</a>
<ul style="display: none; visibility: hidden;">
</li>
Above is an开发者_StackOverflow example of how my dynamaically generated dropdown menu is setup.
The ul is the dropdown menu with links, however I want to disable the About a tag from being clickable. I dont want parents of dropdown to be a link.
I tried:
$('.menuparent').click(function(e) {
e.preventDefault() // or return false;
});
but this code disables the dropdown menu links as well.
Sorry, forgot to mention this menu is generated by Drupal. I don't think I can touch it. I can only work with what I am given.
Try this selector with prev()
:
$('.menuparent > ul').prev('a').click(function(e) {
e.preventDefault();
});
A really simple approach would be to add a class to each of the parent items and use that exact code to target the parent class.
<a title="About" href="/tca/" onClick="javascript:return false;">about</a>
Would this do it?
With an anchor tag the onClick
event is evaluated before the href
is actually followed. If the onClick
event returns a false
the href
is not activated.
精彩评论