jquery - How to highlight a menu link when clicked?

前端 未结 4 928
春和景丽
春和景丽 2021-01-27 17:51

I have a menu with links. The links are placed inside a table. Each link is placed in a . I want to change the background color of the

4条回答
  •  一生所求
    2021-01-27 18:10

    Create a class called .highlight and set it with the desired background color, then just add/remove the class accordingly: http://jsfiddle.net/DdG8m/4/

    $(function() {
        $('#mainMenu td').click(function(e) {
            $('#mainMenu td').removeClass('highlight');
            $(this).addClass('highlight');
        });
    });
    

    note: you will need to use !important on your .highlight class to override any default ones.

提交回复
热议问题