Click here to Skip to main content
15,897,519 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Here is my Menu

C#
<table class="center-style-table">
            
            <tr>
                
                <td>
                    <ul class="subnav">
                <li><a href="/Default.aspx">Hem</a></li>
                <li><a href="/About.aspx">Om oss</a></li>
                <li><a href="~/Apply.aspx">Ansök nu</a></li>
                <li><a href="~/Conditions.aspx">Villkor</a></li>
                <li><a href="~/Faqs.aspx">FAQs</a></li>
                <li><a href="~/Contact.aspx">Kundtjänst</a></li>
                    </ul>
 
               </td>
                     
            </tr>
            
        </table>       


here i am calling subnav.
JavaScript
 <script type="text/javascript" charset="utf-8">
                            jQuery(function () {
                                window.jQuery('.subnav a').each(function () {
                                    if (window.jQuery(this).attr('href') === window.location.pathname) {
                                        window.jQuery(this).addClass('current');
                                    }
                                });
                            });
                        
</script>


here i am setting the style

CSS
.subnav a.current {
        
         border:1px solid white;
            border-radius: 4px 4px 0 0;
            cursor: pointer;
            background-color: white;
            padding-left: 15px;
            padding-right: 15px;
            padding-bottom: 15px;
            padding-top: 15px;
            color: black;
            font-weight: bold;
            text-decoration: none;
            
    }


my problem is when i start the page on page load the default.aspx is set to on page load first, but the default.aspx is not selected, but when i select the default.aspx it gets selected but my other site aboutus.aspx when i select that page my css dont work nothing happens?
Why?
Posted
Comments
Debug and see if it is going inside the each method or not.
Sergejack 24-Apr-14 11:01am    
~/ is not a valid path, it only work in runat="server" tags.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900