Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are overly complicating things. All you need is something like this:</p> <pre><code>$(".nav .js").find(".clicker").on("click", function() { $('.nav .js ul').hide(); $(this).next("ul").toggle(); }); </code></pre> <p>See your updated fiddle: <a href="https://web-beta.archive.org/web/20140320035008/http://jsfiddle.net:80/H3KRk/3/" rel="nofollow noreferrer">http://jsfiddle.net/H3KRk/3/</a></p> <p>Moreover, you need to have at least one common class for your anchors which are menus. For purposes other than menu, use more classes if needed. In your example, the class should be <code>clicker</code> on all menu anchors.</p> <p><strong>Update</strong>:</p> <p>In order to hide menu when clicked outside the menu itself, you need to get the target (using event delegation on document) and then apply this routine to that target anchor only. Something like this:</p> <pre><code>$(document).on("click", function(e) { var $elem = $(e.target); if ($elem.hasClass('clicker')) { $('.nav .js ul').not($elem.next('ul')).hide(); $elem.next("ul").slideToggle(); } else { $('.nav .js ul').hide(); } }); </code></pre> <p>See updated fiddle: <strong><a href="http://jsfiddle.net/H3KRk/4/" rel="nofollow noreferrer">http://jsfiddle.net/H3KRk/4/</a></strong></p> <p><strong>Update 2</strong>:</p> <p>Now, for your fallback to css. You are on the right track. Just a little tweak to your css.</p> <p>See this updated 2: <strong><a href="http://jsfiddle.net/H3KRk/5/" rel="nofollow noreferrer">http://jsfiddle.net/H3KRk/5/</a></strong></p> <p>You need to apply css on inner ul when hovering on li:</p> <pre><code>.nav &gt; .no-js &gt; li:hover &gt; ul { display:block; } </code></pre> <p>instead of <code>.nav .no-js:hover ul</code> as it was in your code.</p> <p>Hope that helps complete all of your problems.</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