All Selector ("*")
Categories: Basic
jQuery('*')
Description: Selects all elements.
-
jQuery('*')
version added: 1.0
Caution: The all, or universal, selector is extremely slow, except when used by itself.
-
Finds every element (including head, body, etc) in the document.
HTML:
<div>DIV</div> <span>SPAN</span> <p>P <button>Button</button></p>
CSS:
h3 { margin: 0; } div,span,p { width: 80px; height: 40px; float:left; padding: 10px; margin: 10px; background-color: #EEEEEE; }
Code:
var elementCount = $("*").css("border","3px solid red").length; $("body").prepend("<h3>" + elementCount + " elements found</h3>");
-
A common way to select all elements is to find within document.body so elements like head, script, etc are left out.
HTML:
<div id="test"> <div>DIV</div> <span>SPAN</span> <p>P <button>Button</button></p> </div>
CSS:
h3 { margin: 0; } div,span,p { width: 80px; height: 40px; float:left; padding: 10px; margin: 10px; background-color: #EEEEEE; } #test { width: auto; height: auto; background-color: transparent; }
Code:
var elementCount = $("#test").find("*").css("border","3px solid red").length; $("body").prepend("<h3>" + elementCount + " elements found</h3>");