I have a jQuery based accordion style navigation that I am trying to modify.
It uses this code:
$('.interior #subContent > ul > li > a.drop').click(function(){
$(this).parent().children('ul').toggle("slow");
return false;
});
I need to be able to keep it open to the section the active page is on. I can highlight the active link with CSS, but could use some good advice for keep it open to the active section.
The navigation is as follows:
<ul>
<li><a href="#" class="drop">Products</a>
<ul>
<li><a href="printing-newproducts.html">New Products</a></li>
<li><a href="printing-inksystems.html">Ink Systems</a></li>
<li><a href="printing-specialtyinks.html">Specialty Inks</a></li>
<li><a href="printing-environmentalinks.html">Environmental Inks</a></li>
<li><a href="printing-whiteplastisolinks.html">White Plastisol Inks</a></li>
<li><a href="printing-plastisolbases.html">Plastisol Bases</a></li>
<li><a href="printing-plastisolinkseries.html">Plastisol Ink Series</a></li>
<li><a href="printing-pvcfreewaterbase.html">Non-PVC Water-Based
System</a></li>
<li><a href="printing-modifersadditives.html">Modifiers & Additives</a></li>
<li><a href="printing-completeproductlisting.html">Complete Product
Listing</a></li>
</ul>
</li>
<li><a href="#" class="drop">Technical Information</a>
<ul>
<li><a href="printing-technicaldatasheets.html">Technical Data Sheets</a></li>
<li><a href="printing-msds.html">MSDS</a></li>
<li><a href="printing-onlinecolorcard.html">Online Color Card</a></li>
<li><a href="printing-mixingsystemsoftware.html">Mixing System Software</a></li>
<li><a href="printing-technicalbulletins.html">Technical Bulletins</a></li>
</ul>
</li>
<li><a href="#" class="drop">Tips & Techniques</a>
<ul>
<li><a href="printing-tradetips.html">Trade Tips</a></li>
<li><a href="printing-galleryoftechniques.html">Gallery of Techniques</a></li>
</ul>
</li>
</ul>
Note: I tried doing this with the jquery ui accordion, but I have a styling conflict with another accordion on the page among other things.
You can see it in action here: It is the sidebar navigation.
Thanks for any assistance.
I got some really solid input from Bryan and jshali above and I wanted to post the final solution, which worked out quite nicely.
Then I add the appropriate class to the list element. It was much easier to add the class than name:
Works nicely thanks for the help.
I'd add a name or class to the 'li' elements so you can target the tab you want and call 'show()' on it in onready:
toggle() actually calls hide()/show(), so in onready call show() on the desired 'ul'
loop over the uls instead of mass acting on them. If you can select an active li under the given ul, then don't shrink it.
Edit: I think this will give you close to what you're wanting, it is a little dry-coded so I'm not 100%, testing is advised.