Skip to content
Related Articles

Related Articles

Improve Article
jQuery | multiple elements Selector
  • Last Updated : 27 Feb, 2019

There are two ways to select multiple elements using selectors:

  • element selector
  • * selector

Syntax:

  • For element selector:
    $("element1, element2, element3, ...")
  • For * selector:
    $("*")

Parameter:

  • element: This parameter is required to specify the elements to be selected.

Example-1: Using element selector.






<!DOCTYPE html>
<html>
  
<head>
    <script src=
  </script>
     
  <script>
        $(document).ready(function() {
            $("h2, div, span").css(
              "background-color", "green");
        });
    </script>
</head>
  
<body>
    <center>
        <h1>Welcome to GeeksforGeeks
      </h1>
        <h2>Geeks1</h2>
  
        <div>Geeks2</div>
  
        <p>Geeks3</p>
        <p><span>Geeks4</span></p>
    </center>
  
</body>
  
</html>

Output:

Example-2: Using * selector.




<!DOCTYPE html>
<html>
  
<head>
    <script src=
  </script>
    <script>
        $(document).ready(function() {
            $("*").css(
            "background-color", "green");
        });
    </script>
</head>
  
<body>
    <center>
        <h1>Welcome to GeeksforGeeks</h1>
        <h2>Geeks1</h2>
  
        <div>Geeks2</div>
  
        <p>Geeks3</p>
        <p><span>Geeks4</span></p>
    </center>
  
</body>
  
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :