How to determine how many jQuery objects are on the page?

Can I determine the number of jQuery objects on a page?

I want to use the number of elements as a kind of weak criterion for page complexity. I think that if I can reduce the number of elements jQuery knows about, the page can work more efficiently.

It makes sense?

Is it as simple as making * selecting and counting results?


Related:
How can I clear the content without waiting for fear, "stop working with this script?" dialogue?

+2
source share
3 answers

http://api.jquery.com/size/

var elementCount = $('*').size();

Although this may be more than what you want:

var elementCount = $('body').find('*').size()
+4
source
var n= 0;
for (var i in jQuery.cache)
    n++;

n , jQuery "" ( , , ).

, , . jQuery 1.4.

, , innerHTML= '', , jQuery . , " ", , , jQuery.cache .

live()/delegate() , . , , , , .

( ; , querySelectorAll, Selectors-API 2).

+3
var elementCount = $('*').length;

jQuery, , .

0

Source: https://habr.com/ru/post/1747429/


All Articles