Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to remove the classstatic selected menu-item using

 $("#slink").removeClass("static selected menu-item");

Thanks guys.I'm sure the Jquery script is running as i have other stuff there. More wider snippet here:

<div id="zz18_TopNavigationMenuV4" class="s4-tn">
    <div class="menu horizontal menu-horizontal">
        <ul class="root static">
            <li class="static selected">
            <a id="slink" class="static selected menu-item" href="/sites/mySite" accesskey="1">
            <span class="additional-background"><span class="menu-item-text">Home</span><span class="ms-hidden">Currently 
            selected</span></span></a></li>
            <ul class="dd_menu root static">
                <li class="static selected">
                <a id="slink" href="/sites/mySite/Tool/default.aspx" class="static selected menu-item">
                <span class="additional-background">
                <span class="menu-item-text">Tool</span></span></a></li>
            </ul>

But no luck so far.Any ideas?

share|improve this question
1  
Your code looks good. I suspect your problem may not be that line of jQuery. I suspect either the HTML is being generated on the fly (by Javascript etc ...) or that jQuery line isn't being called. Can you post a wider example of your code. –  Chris Felstead Nov 28 '11 at 8:19
    
Ensure the jQuery library is being run, can you run the IE dev toolbar and debug your code? That may lead to an issue as well –  David Lozzi Nov 28 '11 at 12:30
    
Thanks guys.I'm sure the Jquery script is running as i have other stuff there. More wider snippet here: –  naijacoder Nov 29 '11 at 0:24
    
I could see a similar post regarding jquery earlier from you. sharepoint.stackexchange.com/questions/23793/… Was that solved? Is this something related? Improving your answer acceptance rate would help you to receive more answers –  Deepu Nair Nov 29 '11 at 3:53
    
I would try the removeClass with one class at a time, I'm not 100% sure that the removeClass method supports multiple classes like that. –  James Love Nov 29 '11 at 9:08
show 1 more comment

1 Answer

When using jQuery or general javascript for that matter, in a ASP.NET masterpage, it's very important that you know where to put it to make sure it takes effect.

If the javascript is placed in the header it is not always certain that the script will be read in time for the element to get affected by it. This can be solved by moving the <script> tag containing the javascript down beneath the HTML which is should have an effect on, like so

<div id="Div1"><p class='class1 class2'>Pretend this is in your masterpage<p></div>
<script type='text/javascript'>
$(document).ready(function () { 
    $('#Div1 p').removeClass('class1 class2');
});
</script>

Hope this helps you.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.