Posted By

kristarella on 10/27/10


jquery thesis thesiswp

Versions (?)

Who likes this?

4 people have marked this snippet as a favorite


Prevent clicking on parent nav links

 / Published in: jQuery

This javascripts stops you from clicking on a nav link when there's a submenu below it, and it adds a class of "noclick" to the link, which you can use with CSS to change the cursor and background colour etc. .menu a.noclick:hover {cursor:default;}

You could change the anchor tag to a span, but that requires more CSS to match the other links.

  1. <script type="text/javascript">
  2. jQuery(function() {
  3. jQuery(".menu li:has('ul') > a").each(function() {
  4. jQuery(this).addClass("nolink").click(function() {
  5. return false;
  6. });
  8. });
  9. });
  10. </script>

Report this snippet  


RSS Icon Subscribe to comments
Posted By: gabrielizaias on October 27, 2010

Use event.preventDefault() instead of return false to preventing the link to be followed.

You need to login to post a comment.