What are jQuery Selectors?


A jQuery Selector is a function which makes use of expressions to find out matching elements from a DOM based on the given criteria.

Selectors are used to select one or more HTML elements using jQuery. Once an element is selected then we can perform various operations on that selected element. jQuery selectors start with the dollar sign and parentheses - $(). You can try to run the following code to learn how to work with jQuery Selectors −

Example

Live Demo

<html>

   <head>
      <title>jQuery Selectors</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

      <script>
         $(document).ready(function() {
            $("p").css("background-color", "yellow");
         });
      </script>
   </head>
   
   <body>
      <div>
         <p class = "myclass">This is a paragraph.</p>
         <p id = "myid">This is second paragraph.</p>
         <p>This is third paragraph.</p>
      </div>
   </body>
   
</html>

Updated on: 13-Feb-2020

149 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements