How can I add a class to the current page and the parent directory page or folder, so I can apply CSS styles?
For example:
root
|- Products
|- Notebook
|- Pencil
|- Bags
Currently visiting: www.domain.com/products/notebooks
<a href="/products" class="current"> Product </a>
<a href="/products/notebook" class="current"> Notebook </a>
<a href="/products/pencil"> Pencil </a>
<a href="/products/bags"> Bags </a>
Result:
Products
Notebooks || Pencil || Bags
I am trying something like this but not success.
push(function() {
var curUrl = location.pathname;
$('a').each(function() {
$(this).toggleClass('current', curUrl.indexOf($(this).attr('href')) != -1);
});