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

后端 未结 4 516
清歌不尽
清歌不尽 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条回答
  •  爱一瞬间的悲伤
    2021-01-30 03:47

    It's quite simple really:

    document.getElementsByTagName('*').length
    

    If you can ignore older browsers, you could also preserve some of the jQuery-like syntax with:

    var $;
    $ = document.querySelectorAll.bind(document);
    $('*').length;
    

提交回复
热议问题