All Selector ("*")

Selects all elements.

.all()

Caution: The all, or universal, selector is extremely slow, except when used by itself.

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.

JS
<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;
}
HTML
var elementCount = $("*").css("border", "3px solid red").length;
$("body").prepend("<h3>" + elementCount + " elements found</h3>");
DEMO

Find all elements within document.body so elements like head, script, etc. are excluded.

JS
<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;
}
HTML
var elementCount = $("#test").find("*").css("border", "3px solid red").length;
$("body").prepend("<h3>" + elementCount + " elements found</h3>");
DEMO

Looking for a Web Developer?

👋

Hi! I'm Basti, author of this site. If you are looking for a web developer with 15+ years of experience, holla at me!

Be it the good 'ol jQuery, vanilla JS or modern frameworks like Vue and Svelte, front- or backend, I can help you.

Just write me at jobs@jqapi.com :)