js怎么实现点击a标签就给他加上一个图片

如图,点击以后加上一个图片,点击别的字母原来的图片就消失,麻烦各位大佬提供一下代码,感谢图片说明图片说明

把所有字母当做一个集合,设置元素的click事件, 选中集合中的一个元素,则让集合中的其他元素恢复正常并给当前元素添加图片

给当前元素加背景图,兄弟元素去掉背景图;或者直接添加类,删除类,类里写选中样式和选中背景图


<a class="tag" onclick="changeImg(this)">111</a>
<a class="tag" onclick="changeImg(this)">222</a>
<a class="tag" onclick="changeImg(this)">333</a>


function changeImg(obj){
    $("a[class=tag]").each(function(i,val){
        $(this).css("background-image","none"); 
    });
    $(obj).css({
        "background-image":"url(/ibms/360/img/arrow.png)",
        "background-repeat":"no-repeat",
        "background-position":"50% 50%",
        "background-size": "100%"
    });
}

如果解决往采纳!

$("a").each(function(){
$(this).click(function(){
$(this).addClass("intro");
$(this).append("");
$($(this).siblings()).removeClass("intro");
$($(this).siblings().children("img")).remove();
});
});

.intro{
font-size:150%;
color:red;
}

例子如下:

$(document).ready(function(){ $("a").each(function(){ $(this).click(function(){ $(this).addClass("intro"); $(this).append("<img></img>"); $($(this).siblings()).removeClass("intro"); $($(this).siblings().children("img")).remove(); }); }); }); .intro{ font-size:150%; color:red; }