I think you can change your hyperlinks to include the correct url. Then in jQuery we check the current URL of browsers with the URL of the hyperlinks - if it matches your menuHeaderActive class.
$(document).ready(function () { var currentUrl = window.location.href; var menuLink = $('.menuHeader a[href="' + currentUrl + '"]'); menuLink.parent().parent(".menuHeader").addClass('menuHeaderActive'); });
When the page reloads after clicking one of the menu links, I have to show that the script should be launched, and $('.menuHeader a[href="' + currentUrl + '"]'); should find the menu link (hyperlink / a-tag) that matches the URL to which the user also connected. Then this is the case of finding the div container and adding your class.
Basically, you do not add the css class when the user clicks a menu link; you should set the css class after redirecting the page to another page. So on another page that should set the css class against the correct link of the active menu. There are 100 ways to do this, but based on the fact that you provided the appropriate URLs is the easiest.
Personally, I will have each page register a page identifier that corresponds to one of the menu links. Something like that...
HTML
Note that the data-related-page-id attribute is added to each menuHeader div
<div class="menuBar"> <div class="menuHeader ui-corner-top" data-associated-page-id="home-welcome"> <span><a href="#" onclick="Home()">Home</a></span> </div> <div class="menuHeader ui-corner-top" data-associated-page-id="energy-catagory-index"> <span><a href="#" onclick="NewTransaction()">New Transaction</a></span> </div> </div>
Javascript
Added to each page
ready-made document handler for the aka ../../ home / welcome welcome page
$(document).ready(function () { SetActiveMenuCssClass('home-welcome'); });
document handler prepared for the energy category index page, aka ../../ EnergyCatagory / index
$(document).ready(function () { SetActiveMenuCssClass('energy-catagory-index'); });
function defined globally
function SetActiveMenuCssClass(pageId) {
If you use a server-side language like PHP, you can do something like fooobar.com/questions/21767 / ...