-1

Is there a way to count children only inside element using jQueru or just javascript?

I tried several methods like:

var count = $(document.body).children().length

or

var count = 0;
$(document.body).children().each(function(){
   count +=1
});

And every single one counts elements even outside of tag even and scripts or styles!

So Is there a way to count elements only inside body tag?

1 Answers1

0

To get the number of elements only inside the body tag, try

var btags = document.body.getElementsByTagName("*");
var count = btags.length;
Cedric Ipkiss
  • 5,662
  • 2
  • 43
  • 72