Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Ok, worked out how to do it, but wanted to know if this is the preferred method of doing it or if there was a better way.

What I have is this..

<script type="text/javascript">
    jQuery(document).ready(function(){

        var menuID = jQuery('#menu-item-814');

        findA = menuID.children('a');
        findA.attr("href", "javascript:void(0);");

    });
</script>
share|improve this question
You could also add a custom class to the links using the Menus area that you want to have the javascript:void(0) attached to. Then you're not locked to the specific post ID. – hereswhatidid Sep 18 '12 at 19:28
1  
what's the purpose of changing the href? you can just preventDefault in a click handler. – Milo Sep 18 '12 at 19:31

closed as off topic by Bainternet Sep 19 '12 at 9:19

Questions on WordPress Answers are expected to relate to WordPress within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

You can also create custom menu items without links, which will create <a>SOME MENU ITEM</a> ie anchor tag without href. In a sense you are creating sort of lower level span that holds some text and you can target it specifically or generally with CSS.

It even validates with transitional doctype. There are numerous discussions about using void(0) vs # vs no href and why each approach is good and why it's bad. The bad thing about what I'm suggesting is that the anchor will not be accessible with non pointer based input devices. On the other hand it's easy to implement and maintain.

On the non-WP part of your question of "Setting parent menu item href to javascript:void(0)" (or actually my answer) try using $('ul.main-menu-or-whatever-yourmenu-class-is').siblings('a').attr("href", "javascript:void(0);"); - this, for instance, will replace the href in all parent menu items wothout the need of targeting ID specifically

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.