Using jQuery I can easily get the number of DOM elements used by a web page:
$('*').length;
But not all web sites are using jQuery.
So my question is: How do I get the number of DOM elements used in a web page using pure JavaScript and js console.
Use offsetWidth & offsetHeight properties of the DOM element to get its the width and height.
While browsers can handle larger DOM trees, they are optimized for a maximum of 32 elements deep. A large DOM tree can harm your page performance in multiple ways: Network efficiency and load performance.
The easiest way to find an HTML element in the DOM, is by using the element id.
Assuming you mean "HTMLElementNodes" as opposed to "All nodes" (which would include such things as text nodes and also be skipped by your jQuery example) then:
document.getElementsByTagName('*').length
This still requires the use of DOM though. Pure JavaScript can't interact with an HTML document other than as a string of text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With