Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would do something like this...</p> <pre><code>$(function() { $("#lang-selector &gt; li").click(function() { $('ul:first',this).toggleClass('active'); }); }); </code></pre> <p>And, then, in the CSS add this:</p> <pre><code>.active { display: block; } </code></pre> <p><strong>&lt;&lt; EDIT: Removed "ul" from ".active" class for CSS rendering efficiency >></strong></p> <p>Also make sure that the sub-nav &lt;ul&gt; has "display: none;" on it by default in your CSS. </p> <p>This will make it so that clicking an &lt;li&gt; tag in #lang-selector, but not in any sub-nav &lt;ul&gt; tags will either open or close the sub-nav, depending on it's current state.</p> <p>If you're worried about the accessibility of having "display: none" on the sub-nav by default, you can do something like this...</p> <pre><code> $(function() { $("#lang-selector li ul").addClass("hidden"); $("#lang-selector li").click(function(e) { e.preventDefault(); $('ul:first',$(this)).toggleClass('hidden active'); }); }); </code></pre> <p><strong>&lt;&lt; EDIT: Altered selectors to match example provided, turned "this" into jQuery object. >></strong></p> <p>And then also add this to the CSS</p> <pre><code>.hidden { display: none; } </code></pre> <p>In this scenario, you have the &lt;ul&gt; showing by default, then when the document loads, jQuery adds the "hidden" class to all of them to hide them, then on the click of the &lt;li&gt; it will toggle the hidden and active classes, displaying them or hiding them. </p> <p>You'll also need to remove your current "display: none" from your #lang-selector ul ul in CSS, otherwise it takes priority over the hidden / active classes.</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. 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