jquery filtering has + not

前端 未结 5 451
离开以前
离开以前 2020-12-01 04:41

Okay I have list items, some have a span, some not.
On my event I want to add the span when they don\'t have any yet.

has() works fine, but

5条回答
  •  盖世英雄少女心
    2020-12-01 05:04

    Try this,

    $("a.add-span").click(function() {
        $("li:not(:has(span))").each(function(index) {
            $(this).append($("").html("Newly Added Span"));
        });
    });
    

提交回复
热议问题