Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This should do the trick. <a href="http://jsfiddle.net/bXX7F/1/" rel="nofollow">jsFiddle</a></p> <pre><code>$(function () { $('#sample2').on('hover', 'li', showSubMenu); $('#sample2').on('mouseleave', hideSubMenus); }); function showSubMenu(){ $(this).siblings().children('ul').hide(100); $(this).children('ul').show(100); } function hideSubMenus(){ $(this).find('ul').hide(100); } </code></pre> <p>EDIT: It seems like you have some confusion about jQuery and how to use selectors (particularly selectors with context e.g. <code>$(selector, context)</code>). </p> <p>In your example, <code>$('#sample2 ul')</code> will select every <code>ul</code> that is a descendant of #sample 2. If you wanted to add the same hover effect to each <code>ul</code>, <code>$('#sample2 ul').hover(handler)</code> or <code>$('#sample2 ul').on('hover', handler)</code> will do that for you. The problem is, you can't hover over hidden items. So what you really want is to select the <code>li</code> under #sample2 and attach your handler to their hover event.</p> <p>Within your hover event handler, you use the selector <code>$('#sample2 ul:eq(0)', this)</code>. The 'this' in that selector provides the context within which the <code>#sample2 ul:eq(0)</code> will be looked for. In an event handler, <code>this</code> refers to the element tied to that event. In this case, the hovered-over <code>li</code>. Eq(0) has no place inside the quotes of the selector, and as a general rule, should be avoided as part of any jQuery selector. Because there is no <code>#sample2</code> element within the context of <code>this</code> and because the <code>:eq(0)</code> malforms the selector, <code>$('#sample2 ul:eq(0)', this)</code> will return an empty jQuery object (nothing selected). What you wanted in your handler was <code>$(this).children('ul')</code>. Which will get the <code>ul</code> that is a direct child of the li currently hovered over.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload