jQuery删除元素

陶塞夫·侯赛因

如果选择了按钮,我基本上是在尝试使用列表类在div中打印按钮的值。取消选择时,还要删除相同的值。我能够成功打印该值,但无法将其删除。有人可以帮我解决这个问题。

var buttonSelect = $(".btn").click(function() {
    if ($(this).hasClass('active')){
        $(".list").append(this.value + "   ")
    }
    else {
        $(".list").remove(this.value)
    }
});
米林德·安纳特瓦尔(Milind Anantwar)

您应该将内容与span等html元素一起附加:

$(".btn").click(function() {
if ($(this).hasClass('active')){
     $(".list").append('<span class="newval_'+this.value+'">'+this.value + "</span>");
}else{ 
     $(".list").find('.newval_'+this.value).remove();
}});

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章