Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my html code

XML
<div id="header">
        <div id="menu">
            <ul class="current_page_itemm">
                <li class="current_page_item"><a href="Home.aspx">Home</a></li>
                <li><a href="JobSeekerlogin.aspx">Jobseeker Profiles</a></li>
                <li><a href="#">Employer Profiles</a></li>
                <li><a href="#">Jobs</a></li>
                <li><a href="#">More</a></li>

</ul>
        </div>
</div>



and here is css code :

CSS
#menu ul {
    margin: 0;
    padding: 25px 0 0 20px;
    list-style: none;
    line-height: normal;
}

#menu li {
    display: block;
    float: left;
}

#menu a {
    display: block;
    float: left;
    margin-right: 17px;
    padding: 5px 8px;
    text-decoration: none;
    font: 20px Georgia, "Times New Roman", Times, serif;
    color: #FFFFFF;
}

#menu a:hover {
    text-decoration: underline;
    background: #910000;
    color:#FFFFFF;
 }


#menu a:active{
    background: #910000;
    color:black;
}


plz help me to get the color change effect after clicking of any tab so that user should know under which tab they are working?
Posted

1 solution

jQuery


Little bit of jQuery would do this trick. We are adding a class ('selected') dynamically on click of Tab.
JavaScript
$(document).ready(function () {
    $('#menu ul li a').click(function (ev) {
        $('#menu ul li').removeClass('selected');
        $(ev.currentTarget).parent('li').addClass('selected');
    });
});

CSS


CSS
#menu ul li.selected {
    background: #910000;
    color:#FFFFFF;
}

Demo


[Demo] Change Background Color of Tab on Tab Click[^]
 
Share this answer
 
Comments
HellHotie 24-Jun-14 13:57pm    
I tried it but is not yet working
Did you see the Demo? It is working correctly. See what exactly you are missing. If you face further issues, then reply me.
HellHotie 15-Jul-14 16:21pm    
i am using asp.net and my menu is on masterpage. problem is still there i can get hovering effect and everythng just problem is with after click. i tried with your code too
I guess the id of menu is different. Can you just see the source html and check the id of menu?
HellHotie 16-Jul-14 4:41am    
I am posting css code again

/* Menu */

#menu {
float: left;
width: 680px;
height: 40px;
}

#menu ul {
margin: 0;
padding: 25px 0 0 20px;
list-style: none;
line-height: normal;
}

#menu li {
display: block;
float: left;
}

#menu a {
display: block;
float: left;
margin-right: 17px;
padding: 5px 6px;
text-decoration: none;

font: 18px 'Open Sans', Helvetica, sans-serif;

color: #FFFFFF;
}

#menu a:hover {
text-decoration: underline;
background: #910000;
color:#FFFFFF;
}


#menu a:active{
background: #910000;
color:black;
}


#menu ul li.selected {
background: #910000;
color:#FFFFFF;
}

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