user1471980
user1471980

Reputation: 10626

Changing background color of the tab jquery

I am using jquery to change the font and background color of the tab when selected. When I pick a tab, font change works but background color does not work. Can anybody have input on what I am doing wrong?

Jquery script:

<script type="text/javascript">
$(document).ready(function() {

    $('.tabs a').click(function(){
        switch_tabs($(this));
    });

    switch_tabs($('.defaulttab'));

});

function switch_tabs(obj)
{
    $('.tab-content').hide();
    $('.tabs a').removeClass("selected");
    var id = obj.attr("rel");

    $('#'+id).show();
    obj.addClass("selected");
} 
</script>

css code:

ul.tabs li a {
    display:block;
    float:left;
    padding:3px;
    font-size:1em;
    background-color: #e0e0e0;
    color:black;
    text-decoration:none;
    border-color: white;
}
.selected {
    font-weight:bold;
    background-color:#3399FF;
    color:white;
}

Upvotes: 1

Views: 3721

Answers (1)

iambriansreed
iambriansreed

Reputation: 22241

Change the CSS selector:

From .selected to ul.tabs li a.selected.

Upvotes: 1

Related Questions