给一个ul列表中点击到的li赋予样式,并移除兄弟节点的此样式
程序员文章站
2022-07-14 22:53:31
...
<div class="list-group" id="myList">
<a href="#" class="list-group-item list-group-item-action" id = "letActive"> Cras justo odio </a>
<a href="#" class="list-group-item list-group-item-action active">Dapibus ac facilisis in</a>
<a href="#" class="list-group-item list-group-item-action">Morbi leo risus</a>
<a href="#" class="list-group-item list-group-item-action">Porta ac consectetur ac</a>
<a href="#" class="list-group-item list-group-item-action " >Vestibulum at eros</a>
</div>
$(".list-group-item").click(function () {
$(".list-group-item").siblings("a").removeClass("active");
$(this).addClass("active");
});
上一篇: python基础~4(tuple)
下一篇: 10.24 JQ继续DOM操作