Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery addclass and remove class not updating properly
    text
    copied!<p>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</p> <pre><code>$(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 ); }); } </code></pre> <p>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.</p> <p>This is the ASPMenu declaration</p> <pre><code>&lt;SharePoint:AspMenu ID="TopNavigationMenuV4" Runat="server" EnableViewState="false" DataSourceID="topSiteMap" AccessKey="&lt;%$Resources:wss,navigation_accesskey%&gt;" UseSimpleRendering="true" UseSeparateCss="false" Orientation="Horizontal" StaticDisplayLevels="2" MaximumDynamicDisplayLevels="2" SkipLinkText="" CssClass="s4-tn"/&gt; </code></pre> <p>Why is this happening. Appreciate any helps. Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload