I have a SharePoint ASPMenu in a MasterPage, I;m trying to change the selected style class using jQuery. Basically when user click a menu item it will cause postback so that the page will be directed to the clicked menu url. When the user clicked on a menu item I put the url in the cookie. Then when the page load I'll set the style for the selected menu. Here are my code so far
$(document).ready(function () {
LinkClicked();
FireMe();
});
function FireMe()
{
var val = $.cookie('sabValue');
if(val !== null)
{
$(".s4-tn a").each(function(){
$(this).removeClass("selected").closest("li").removeClass("selected");
});
$(".s4-tn a[href='"+val+"']").addClass("selected").closest("li").addClass("selected");
}
}
function LinkClicked(){
$(".s4-tn a").click(function() {
var sabValue = $(this).attr("href");
$.cookie('sabValue',sabValue );
});
}
My problem is, after the page load (after the user clicked a menu) the changes does not take place. I have to clicked the menu item again so that the selected style is applied. This is the Menu declaration:-
<SharePoint:AspMenu
ID="TopNavigationMenuV4"
Runat="server"
EnableViewState="false"
DataSourceID="topSiteMap"
AccessKey="<%$Resources:wss,navigation_accesskey%>"
UseSimpleRendering="true"
UseSeparateCss="false"
Orientation="Horizontal"
StaticDisplayLevels="2"
MaximumDynamicDisplayLevels="2"
SkipLinkText=""
CssClass="s4-tn"/>
Why is this happening. Appreciate any helps. Thanks