superfish - How to disable the top level links

545 views Asked by At

I use superfish Menu Plugin - v1.7.4 and I want to disable the links of the top level.

I tried the following:

$(document).ready(function() {  
  // does not work 1:
  $('div#block_top_menu > ul.sf-menu > li > a.sf-with-ul').bind('click', false); // only direct children  

  // does not work 2:
  $('div#block_top_menu > ul.sf-menu > li > a.sf-with-ul').attr("href", "#"); // disable top-level links by replacing with #s

  // does not work 3:      
  $('div#block_top_menu > ul.sf-menu > li > a.sf-with-ul').click(function(){
            return false; // disable browser default when link is clicked
  })

});

but none of them helped.

Probably all related to elder versions of superfish or to other plugins.

so, How can I disable the top level links?

2

There are 2 answers

0
Atara On BEST ANSWER

I use

$('div#block_top_menu > ul > li > a').attr("href", "#");

as @charlietfl advised: sf* classes are added later so I cannot use them in the selector...

3
unalignedmemoryaccess On

Personally, for me this method always work:

HTML:

<a href="mylink.php" id="mylink">Link here</a>

JS:

jQuery(document).ready(function() {
    jQuery('#test').unbind('click').bind('click', function(e) {
         e.preventDefault(); //Prevent default behavior
         return false;
    });
});

Method first unbinds any click method and then binds our method.