Note that there are some explanatory texts on larger screens.

plurals
  1. POMaking jQuery display the correct sub-menu, when present
    primarykey
    data
    text
    <p>this is my first post here so I apologise in advance for any poor practise. I've been searching for a while, but haven't come across a solution that fits my needs as yet - maybe I'm just doing it wrong. But here goes:</p> <p>I'm building a site using the Big Cartel CMS and have delved into jQuery for the first time. I'm trying to create a horizontal and centred navigation menu that will display a sub-menu underneath, where appropriate. I'm fine with html and CSS, but am struggling with the jQuery.</p> <p>The mark-up is as follows:</p> <pre><code>&lt;nav&gt; &lt;ul id="mainNav"&gt; &lt;li&gt;&lt;a href="expand-the-sub-menu"&gt;Option 1&lt;/a&gt; &lt;ul id="option1Nav"&gt; &lt;li&gt;&lt;a href="somewhere"&gt;Option 1 Link 1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="somewhere"&gt;Option 1 Link 2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="somewhere"&gt;Option 1 Link 3&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="somewhere"&gt;Option 1 Link 4&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="somewhere"&gt;Option 1 Link 5&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="expand-the-sub-menu"&gt;Option 2&lt;/a&gt; &lt;ul id="option2Nav"&gt; &lt;li&gt;&lt;a href="somewhere"&gt;Option 2 Link 1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="somewhere"&gt;Option 2 Link 2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="somewhere"&gt;Option 2 Link 3&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="somewhere"&gt;Option 2 Link 4&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="somewhere"&gt;Option 2 Link 5&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="somewhere"&gt;Option 3&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="somewhere"&gt;Option 4&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="somewhere"&gt;Option 5&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="somewhere"&gt;Option 6&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/nav&gt; </code></pre> <p>Whilst this format will not change, the number of options with sub-menus might (the client can change this at will). My jQuery so far:</p> <pre><code>$('#mainNav ul').hide(); $('#mainNav li a').click(function(){ $('#mainNav li:has("ul")').each( function(){ $('nav').animate({bottom:'60px'},300,'easeOutQuint',function(){ //Do magic stuff here - i.e. display the correct sub-menu. }); } ); }); </code></pre> <p>Currently, this targets all options (I can't fathom why) when clicked, and I've still not got to the bottom of how to only display the appropriate sub-menu. Classes may be added to any html elements, if that helps to make things easier.</p> <p>Thanks in advance!</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.
 

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