Note that there are some explanatory texts on larger screens.

plurals
  1. PONav/Subnav list, how to give clicked item active class after reload of page
    primarykey
    data
    text
    <p>I have a couple nested &amp; hidden sub-nav lists</p> <pre><code>&lt;ul class="nav"&gt; &lt;li&gt;&lt;a href="index.html"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="profile" href="#"&gt;Profile&lt;/a&gt; &lt;ul id="profile"&gt; &lt;li&gt;&lt;a href="company.html"&gt;Company&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="structure.html"&gt;Structure&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="team.html"&gt;Team&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a class="projects" href="#"&gt;Projects&lt;/a&gt; &lt;ul id="projects"&gt; &lt;li&gt;&lt;a href="chapter.html"&gt;Chapter&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="pblc-trde.html"&gt;Pblc Trde&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="globe.html"&gt;Globe&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="komforte.html"&gt;Komforte&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; </code></pre> <p></p> <p>I am currently using some jQuery i found online to show/hide the sub-nav upon click. What I am trying to accomplish is:</p> <ol> <li><p>Hopefully clean up the show/hide click function of the sub-nab menus.</p></li> <li><p>When clicking on the sub-nav menu items, the corresponding page that opens, needs to have the sub-nav expanded and give the corresponding menu item active class, so as to let the user know which page they are on.</p></li> <li><p>I am hoping to do this purely in JS/jQuery. The installation of the site will be in WordPress. </p> <pre><code>$(document).ready(function () { $(".profile").click(function () { var X = $(this).attr('id'); if (X == 1) { $("#profile").hide(); $(this).attr('id', '0'); } else { $("#profile").show(); $(this).attr('id', '1'); } }); //Mouse click on nav $("#profile").mouseup(function () {}); //Document Click $(document).mouseup(function () { $("#profile").hide(); $(".profile").attr('id', ''); }); $(".projects").click(function () { var X = $(this).attr('id'); if (X == 1) { $("#projects").hide(); $(this).attr('id', '0'); } else { $("#projects").show(); $(this).attr('id', '1'); } }); //Mouse click on nav $("#projects").mouseup(function () {}); //Document Click $(document).mouseup(function () { $("#projects").hide(); $(".projects").attr('id', ''); }); }); window.onload = function () { $("ul#profile li:first").addClass("active"); }; $(document).ready(function () { $("ul#profile").show() }); </code></pre></li> </ol>
    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