I have a couple nested & hidden sub-nav lists
<ul class="nav">
<li><a href="index.html">Home</a></li>
<li><a class="profile" href="#">Profile</a>
<ul id="profile">
<li><a href="company.html">Company</a></li>
<li><a href="structure.html">Structure</a></li>
<li><a href="team.html">Team</a></li>
</ul>
</li>
<li><a class="projects" href="#">Projects</a>
<ul id="projects">
<li><a href="chapter.html">Chapter</a></li>
<li><a href="pblc-trde.html">Pblc Trde</a></li>
<li><a href="globe.html">Globe</a></li>
<li><a href="komforte.html">Komforte</a></li>
</ul>
</li>
I am currently using some jQuery i found online to show/hide the sub-nav upon click. What I am trying to accomplish is:
Hopefully clean up the show/hide click function of the sub-nab menus.
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.
I am hoping to do this purely in JS/jQuery. The installation of the site will be in WordPress.
$(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() });