Get all elements without child node in jQuery

前端 未结 4 597
忘掉有多难
忘掉有多难 2020-11-27 19:33

I need to select elements without child node (including text since in

text is a child node).

I used empty, but it also consider

4条回答
  •  攒了一身酷
    2020-11-27 20:08

    I think you can try this:

    $('span').filter(function() {
       return !this.innerHTML.replace(/\s/g,'').length;
    });
    

    DEMO

提交回复
热议问题