Skip to content
Related Articles

Related Articles

jQuery * Selector

View Discussion
Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 11 Jul, 2022
View Discussion
Improve Article
Save Article

jQuery is an open-source JavaScript library that simplifies the interactions between an HTML/CSS document, or more precisely the Document Object Model (DOM), and JavaScript. Elaborating the terms, it simplifies HTML document traversing and manipulation, browser event handling, DOM animations, Ajax interactions, and cross-browser JavaScript development.

The jQuery * selector selects all the elements in the document, including HTML, body, and head. If the * selector is used together with another element then it selects all child elements within the element used.

Syntax:

$("*")

Parameters:

  • *: This parameter is used to select all elements.

Example 1: Selects all element and change background color. 

HTML




<!DOCTYPE html>
<html>
<head>
  <script src=
  </script>
  <script>
    $(document).ready(function () {
      $("*").css("background-color",
        "lightgreen");
    });
  </script>
</head>
<body>
  <center>
    <h1>Welcome to geeksforgeeks
    </h1>
     
<p>My name is akash.</p>
 
     
<p>I live in mathura.</p>
 
     
<p>My best friend is ajay.</p>
 
     
<p>Who is your favourite:</p>
 
    <ul type="square">
      <li>virat</li>
      <li>akshay</li>
    </ul>
  </center>
</body>
</html>

Output:

Example 2: Selects all element and change background color. 

HTML




<!DOCTYPE html>
<html>
<head>
  <script src=
  </script>
  <script>
    $(document).ready(function () {
      $("*").css("background-color",
        "green");
    });
  </script>
</head>
<body>
  <h1>GeeksForGeeks</h1>
   
<p>cricket is religion in india</p>
 
   
<p>sachin is god of cricket.</p>
 
   
<p>records:</p>
 
  <ul type="circle">
    <li>100 centuries</li>
    <li>highest run scorer</li>
  </ul>
</body>
</html>

Output: 

Supported Browsers:

  • Internet Explorer 9.0
  • Firefox 3.6
  • Safari 4.0
  • Opera 10.5

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!