How to get the number of DOM elements used in a web page

后端 未结 4 512
清歌不尽
清歌不尽 2021-01-30 02:56

Using jQuery I can get easily the number of DOM elemetns used by a web page:

$(\'*\').length;

But not all web sites are using jQuery.

4条回答
  •  梦毁少年i
    2021-01-30 03:38

    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.

提交回复
热议问题