Adam
Adam

Reputation: 9049

disabling <a> parent link of a dropdown menu

<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 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.

Upvotes: 0

Views: 1079

Answers (3)

gingerbreadboy
gingerbreadboy

Reputation: 7769

<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.

Upvotes: 0

Todd
Todd

Reputation: 676

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.

Upvotes: 0

No Results Found
No Results Found

Reputation: 102745

Try this selector with prev():

$('.menuparent > ul').prev('a').click(function(e) {
    e.preventDefault();
});

Upvotes: 2

Related Questions