Home / jQuery / Get the number of elements in a page

Get the number of elements in a page

If you are very much concerned about performance of your website or webpage, you must surely get into practice of finding out useless elements used. This would not give a very high performance but a good practice and can be assured of minute lag issue.

console.log('This page has ' + $('*').length + ' elements!');

In the above snippet * indicates all elements of the page. This universal selector is passed to jQuery and the count is logged. You can play with the output by using alert() or store into variables.

About Ashik

I am a Full Stack Developer and love to work on APIs and Apps. Hardcore lover of Ionic and Laravel <3

Check Also

Private chatroom using socket.io, NodeJS and MySQL

As I promised to write a tutorial on Private chatroom with MySQL DB in the …

Do you wan't to get notified?

I will not spam your inbox. I will only send email whenever I publish a new article or to share information about technology

You have Successfully Subscribed!