jQuery Selector How to - Find all elements within the 'context' (document.body)








Question

We would like to know how to find all elements within the 'context' (document.body).

Answer


<!--  w w  w .ja va2  s . c o  m-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("*", document.body).css("border","3px solid red");
        });
    </script>
  </head>
  <body>
          <div>A div</div>
          <button>0</button>
          <button>1</button>
          <button>2</button>
          <button>3</button>
          <span></span>
  </body>
</html>

The code above is rendered as follows: