jQuery API

All Selector (“*”)

all selector

version added: 1.0jQuery('*')

Description: Selects all elements.

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

Examples:

Example: Finds every element (including head, body, etc) in the document.

<!DOCTYPE html>
<html>
<head>
  <style>
  h3 { margin: 0; }
  div,span,p {
    width: 80px;
    height: 40px;
    float:left;
    padding: 10px;
    margin: 10px;
    background-color: #EEEEEE;
  }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <div>DIV</div>

  <span>SPAN</span>
  <p>P <button>Button</button></p>
<script>var elementCount = $("*").css("border","3px solid red").length;
$("body").prepend("<h3>" + elementCount + " elements found</h3>");</script>

</body>
</html>

Demo:

Example: A common way to select all elements is to find within document.body so elements like head, script, etc are left out.

<!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>
</head>
<body>
  <div id="test">
  <div>DIV</div>
  <span>SPAN</span>
  <p>P <button>Button</button></p>
</div>
<script>
var elementCount = $("#test").find("*").css("border","3px solid red").length;
$("body").prepend("<h3>" + elementCount + " elements found</h3>");</script>

</body>
</html>

Demo:

Support and Contributions

Need help with All Selector (“*”) or have a question about it? Visit the jQuery Forum or the #jquery channel on irc.freenode.net.

Think you've discovered a jQuery bug related to All Selector (“*”)? Report it to the jQuery core team.

Found a problem with this documentation? Report it on the GitHub issue tracker

  • Dmitry Shkurkin

    How to get the id of the last DOM element on which the clicked on the page?

    • inspire22

      You could track clicks on all dom elements then store it for later re-use

      var e;
      $('*').live('click', function() {
      e = $(this)
      }

  • sreeramya7

    could you please mention the element names also..i couldnt get the 12 elements in the first example

    • Gking Learn

      Missed out “!DOCTYPE html”

    • Gking Learn

      “!DOCTYPE html”, html, head, style, script, body, div, span, P, Button & script are the 11 elements.

  • Peace Of Kake

    the indentation of the 2nd example is off

  • Suchai_W55

    (“*”)l(“.”),(“'”)l(“L”),(“_l_”)l(“-l-”),(“+l+”)l(“!l!”).
    Happy New Year(2554.),(2011),to Someone,Happy and Lucky and Funny and Love.

  • Suchai_W55

    (“*”)l(“.”),(“'”)l(“L”),(“_l_”)l(“-l-”),(“+l+”)l(“!l!”).
    Happy New Year(2554.),(2011),to Someone,Happy and Lucky and Funny and Love.

  • Micha

    you don’t test it right?
    a var wich is defined in a function coulden’t be re-use later.

  • Fee

    qqd123网址之家,http://www.qqd123.com/,人们都在用的电脑主页!

    • Asdf

      speak english

  • Asdf

    speak english