01
Nov
Learn how to use jQuery All Selector (“*”)
All Selector (“*”)
This will select all elements.
Caution: The all, or universal, selector is extremely slow, except when used by itself.
Example 01:
Find every element (including head, body, etc) in the document. Note that if your browser has an extension/add-on enabled that inserts a script or link element into the DOM, that element will be counted as well.
<script> var elementCount = $("*").length; </script>
Example 02:
A common way to select all elements is to find within document.body so elements like head, script, etc are left out.
<script> var elementCount = $("#test").find("*").length; </script>