jQuery CSS Universal Selector

« Previous Chapter Next Chapter »

Description:

The universal selector selects all the elements available in the document.

Syntax:

Here is the simple syntax to use this selector:

Example

 $('*')
                                        

Parameters:

Here is the description of all the parameters used by this selector:

  • *: A symbolic star.

Returns:

Like any other jQuery selector, this selector also returns an array filled with the found elements.

Example:

  • $('*') selects all the elements available in the document.

Following example would select all the elements available and would display them one by one:

Example

<html>
<head>
<title>The Selecter Example</title>
<script type="text/javascript" src="../../js/jquery-2.2.0.js">
</script>
   
<script type="text/javascript" language="javascript">
  $(document).ready(function() {
      var elements = $("*");
      for( i=0; i<elements.length; i++ ){
         alert("Found element: " + elements[i].innerHTML);
      }
   });
</script>
</head>
<body>
<div class="big" id="divid1">
  <p class="para1" id="pid1">This is first paragraph.</p>
  <p class="para2" id="pid2">This is second paragraph.</p>
  <p class="para3" id="pid3">This is third paragraph.</p>
</div>
<br />
<div class="big" id="divid2">
  <p>This is second division of the DOM.</p>
  <p>This is second para inside second division.</p>
</div>
<br />
<div class="medium" id="divid3">
  <p>A para inside third division</p>
</div>
</body>
</html>
                                        
Code It Online

« Previous Chapter Next Chapter »

Have Any Suggestion? We Are Waiting To Hear from YOU!

Your Query was successfully sent!