html – 按属性条件删除某些div

我有类似的东西

如何删除“data-count”属性值小于15的div?

最佳答案
这样更有效,因为它只选择具有data-count属性的div,并且只为每个元素构造一次jQuery对象:

$('div[data-count]').each(function () {
    var $this = $(this);

    if ($this.attr('data-count') < 15) {
        $this.remove();
    }
});

演示:

$('button').on('click',function () {
    $('div[data-count]').each(function () {
        var $this = $(this);

        if ($this.attr('data-count') < 15) {
            $this.remove();
        }
    });
});
div[data-count]:before {
    content: "