Last week I created an e-shop with opencart. Now I’m trying to customize the default top menu. What I want to do is to keep the parent highlighted even when a child element is selected
I highlight the current page with this js :
<script type="text/javascript" >
function extractPageName(hrefString)
{
var arr = hrefString.split('/');
return (arr.length < 2) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase();
}
function setActiveMenu(arr, crtPage)
{
for (var i=0; i < arr.length; i++)
{
if(extractPageName(arr[i].href) == crtPage)
{
if (arr[i].parentNode.tagName != "DIV")
{
arr[i].className = "current";
arr[i].parentNode.className = "current";
}
}
}
}
function setPage()
{
hrefString = document.location.href ? document.location.href :document.location ;
if (document.getElementById("menu") !=null)
setActiveMenu(document.getElementById("menu").getElementsByTagName("a"),extractPageName(hrefString));
}
window.onload=function()
{
setPage();
}
</script>
Any help would be greatly appreciated.
p.s. sorry for my English, if you can’t understand what I want to make.
I figured it out. Tooraj gives me the idea. Here is my code :