For example, I have https://../pc/ and for example there is a category in https://../pc/soft and there is news in these categories https://../pc/0_291q_ob_zor or https://../pc/soft/0-1-test .
How to add an active class to them? That's what i have
<div id='cssmenu'> <ul> <li><a href='//xxx.xx/'><span>На главную</span></a></li> <li class='active has-sub'><a href='//xxx.xx/pc/'><span>PC</span></a> <ul> <li class='has-sub'><a href='//xxx.xx/pc/soft/'><span>Soft</span></a> <ul> <li><a href='#'><span>...</span></a></li> <li class='last'><a href='#'><span>...</span></a></li> </ul> </li> <li class='has-sub'><a href='//xxx.xx/android/'><span>Android</span></a> <ul> <li><a href='//xxx.xx/android/soft/'><span>Soft</span></a></li> <li class='last'><a href='#'><span>Sub Product</span></a></li> </ul> </li> </ul> </li> </ul> </div> There is a script, but it does not work when you go for example to the news, or it does not add to the sub categories AND categories.
$(function () { $('#cssmenu > ul > li > a').each(function () { var location = window.location.href; var link = this.href; if(location == link) { $(this).closest("li").addClass('active'); } }); });