Change background image of <li> on click of <a> tag

纵然是瞬间 提交于 2019-12-03 21:48:58

Try this

$("li").click(function(){
    $("li").removeClass("active");
    $(this).addClass("active");
  });

CSS for the new active class is

li.active {
   background-image: url(../images/btnSelectedTab.png);
   color: black;
}

Create a class for what you wish the active li tag to look like; and use the following:

$('li').click(function(){
    $(this).addClass('active').siblings().removeClass('active');
});

This should affect only list items within the same ul tag.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!