javascriptjqueryjquery-uisubmenujquery-ui-menu

Disable the opening of submenu in jquery menu on hover


I am using jquery menu in my application.I have 3 levels of submenu. Like the one shown in the jsfiddle below.

http://jsfiddle.net/ankitap/WC3bE/

When we do mouse hover on the menu options,the submenu will open automatically. I want to disable this feature and want to open the submenu only on click. i tried to use:

$( "#menu a" ).menu({ role: null });

I have also tried to give level 1 class name as mainclass and level 2 class name as subclass.

      <script>
      $("#menu").menu();
      $("#menu a").click(function() {
      console.log($(this).text()); // gets text contents of clicked li
      $(".subclass a").show();  
      });

      $("#menu a").click(function() {
      $(".subclass a").hide();
      });
      </script>

the html code for this is:

<ul id="menu" class="mainclass">
  <li><a href="#">Aberdeen</a></li>
  <li><a href="#">Ada</a></li>
  <li><a href="#">Adamsville</a></li>
  <li><a href="#">Addyston</a></li>
  <li>
    <a href="#">Delphi</a>
    <ul class="subclass">
      <li >
          <a href="#">Ada</a>
          <ul>
              <li>
                  <a href="#">ankita</a>              
              </li>
          </ul>    
      <li><a href="#">Saarland</a></li>
      <li><a href="#">Salzburg</a></li>
    </ul>
  </li>
  <li><a href="#">Saarland</a></li>
  <li>
    <a href="#">Salzburg</a>
    <ul class="subclass">
      <li>
        <a href="#">Delphi</a>
        <ul>
          <li><a href="#">Ada</a></li>
          <li><a href="#">Saarland</a></li>
          <li><a href="#">Salzburg</a></li>
        </ul>
      </li>
      <li>
        <a href="#">Delphi</a>
        <ul>
          <li><a href="#">Ada</a></li>
          <li><a href="#">Saarland</a></li>
          <li><a href="#">Salzburg</a></li>
        </ul>
      </li>
      <li><a href="#">Perch</a></li>
    </ul>
  </li>
  <li><a href="#">Amesville</a></li>
</ul>

I could not stop the opening of submenu on mouse hover. I want the submenu to open only after click.Please help! Thank you.


Solution

  • no js/jquery guru but maybe unbind mouseenter and mouseleave events

    $("#menu").menu(/*{
    select: function( event, ui ) {
      var selection = ui.item.text();
      var  get=this.event;
      console.log(get);
    }}*/);
    $('#menu').unbind('mouseenter mouseleave');
    $("#menu a").click(function() {
      console.log($(this).text());
    });
    

    note the $('#menu').unbind('mouseenter mouseleave'); statement