Active Menu Highlight CSS

后端 未结 11 891
孤独总比滥情好
孤独总比滥情好 2020-11-29 00:54

I want to highlight the current menu you have click. I\'m using CSS, but it is now working.

here is my css code:

#sub-header ul li:hover{ background-         


        
11条回答
  •  自闭症患者
    2020-11-29 01:40

    You should refer to the current element and not all elements matching your selector.

    $("#mainMenu td").click(function() {
    $(this).css('background-color', '#EDEDED');
    

    });

    I´d also recommend you to use CSS classes instead of setting the CSS properties this way.

    That would be something like;

    $("#mainMenu td").click(function() {
    $(this).addClass('selected');
    

    });

    together with;

    #mainMenu td.selected {
    

    background-color: #EDEDED; }

提交回复
热议问题