Code: $(".menu a[@href$=cat/5]").parent().addClass("active").parents("ul").show().addClass("open"); $(".menu a[@href$=cat/5]").parents("li").addClass("open"); Can this be simplified to a single line? (or in anyway?) Relevant HTML: Code: <ul class="menu hier open"> ... <li id="menu2" class="parent open">Peripherals <ul> <li id="menu3"><a href="/cat/3">Input</a></li> <li id="menu4" class="parent">Output <ul> <li id="menu5"><a href="/cat/5">CRT/LCD Monitor</a></li> <li id="menu6"><a href="/cat/6">VFD/LCD Panel</a></li> ... </ul> </li> </ul> </li> ... </ul> Any suggestions welcome see http://beta.scc.jezmckean.com/cat/5
I assume you're generating the jQuery dynamically based off the current URL, right? Wouldn't it be easier to just add the classes dynamically to the list instead, or is that not a feasable option? You can try Code: $(".menu a[@href$=cat/5]").parent().addClass("active").parents("ul, li").show().addClass("open"); but no guarantees. If that dual selector doesn't work, I don't think it's otherwise possible without needlessly complex DOM traversal.
Yep, it should be but the function is recursive and complex enough already. Will give it a go. Okay, many thanks.