jQuery * Selector

Last Updated : 11 Jul, 2025

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

<html>
  
<head>
    <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
    script>
  
    <script>
        $(document).ready(function () {
            $("*").css("background-color",
                "lightgreen");
        });
    script>
head>
  
<body>
    <center>
        <h1>Welcome to geeksforgeeksh1>
        <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>viratli>
            <li>akshayli>
        ul>
    center>
body>
  
html>

Output:

Example 2: Selects all element and change background color. 

HTML

<html>
  
<head>
    <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
    script>
  
    <script>
        $(document).ready(function () {
            $("*").css("background-color",
                "green");
        });
    script>
head>
  
<body>
    <h1>GeeksForGeeksh1>
    <p>cricket is religion in indiap>
    <p>sachin is god of cricket.p>
    <p>records:p>
    <ul type="circle">
        <li>100 centuriesli>
        <li>highest run scorerli>
    ul>
body>
  
html>

Output: 

Comment

Explore