this also applies to this other thread: jQuery - If the url matches href, then move the LI to the beginning of UL?
JQuery Code:
//set var to current url var url = window.location.toString(); //if url matches li anchor then bring it to the top of the list $('.nav li a').each(function(){ var myHref= $(this).attr('href'); if( url == myHref) { $(this).closest("li").prependTo(".nav"); } });
HTML is only found from Wordpress Navigation, so something like:
<navrole="navigation"> <ul> <li> <a href="">
Navigation points to categories, and the URL matches href fine and the code works. But I canβt figure out how to get the code that will fire when Iβm on the categoryβs child page, for example, when the URL:
domain.com/category-name/child-page
If I can get JQuery to detect only the first path outside the domain, then I will be golden. Everything that happened behind the first blank name can be omitted or configured as a wild card or something like that.
Any ideas?
source share