1

div、p、および span タグを含む DOM 構造があります。子ノードを含む「p」タグと、子ノードを含まない「p」タグを数えたいと思います。このフォーラムで解決策を読みましたが、うまくいきません: How to check if element has any children in Javascript? . フィドルのデモ

$('#test').blur(function(){
    var test= $('.check p').filter(function (){
    if ($(this).childNodes.length > 0)
        return this
    });
    alert(test.lenght)
})
4

3 に答える 3