I have a DOM structure with div, p and span tags. I want to count the 'p' tags with children nodes and that without any children. I read a solution in this forum, but it doesn't work for me: How to check if element has any children in Javascript?. Fiddle demo
$('#test').blur(function(){ var test= $('.check p').filter(function (){ if ($(this).childNodes.length > 0) return this }); alert(test.lenght) })