all selector
Description: Selects all elements.
jQuery('*')
version added: 1.0
Caution: The all, or universal, selector is extremely slow, except when used by itself.
Examples
Example 1
Finds every element (including head, body, etc).Example 1 - Full source:
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function(){ $("*").css("border","3px solid red"); }); </script> <style> div,span,p { width: 150px; height: 60px; float:left; padding: 10px; margin: 10px; background-color: #EEEEEE; } </style> </head> <body> <div>DIV</div> <span>SPAN</span> <p>P <button>Button</button></p> </body> </html>
Example 2
A common way to select all elements is to find within document.body so elements like head, script, etc are left out.Example 2 - Full source:
<!DOCTYPE html>
<html>
<head>
<style>
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;
}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function(){
var elementCount = $("#test").find("*").css("border","3px solid red").length;
$("body").prepend("<h3>" + elementCount + " elements found</h3>");
});
</script>
</head>
<body>
<div id="test">
<div>DIV</div>
<span>SPAN</span>
<p>P <button>Button</button></p>
</div>
</body>
</html>
Was this information helpful?

