Click a label to add a class style to it and delete the class style of its sibling elements.
//Click event,
$(".user-menu li a").click(function(){
//单击时,给他添加样式,同时遍历同辈元素删除该样式
//但是实现不了,是不是我的思路错了
$(this).addClass("active").siblings().removeClass("active");
});
//Tag, there is an a tag in the li tag. Initially, only the collection vehicles have styles, I don’t know why it cannot be displayed.
<ul class="user-menu">
<li> ;Collect vehicles</li>
<li>Price reduction reminder</li>
<li>Browsing history</li>
</ul>
When not clicked
After clicking, you want to add a demonstration to the label you want to click. Delete the style of the original label, leaving only one style
What you want to achieve after clicking is not achieved
$(".user-menu li a").click(function(){
});
This is how I usually use it, and I’d like to ask for a better solution;
Supplement: Your selector selects the a tag inside the li tag, and then you look for the sibling elements of the a tag, but you can’t find other li The a tag under the tag.
First traverse all elements, then add a style to the current one, and remove this style from the others
My plan: