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 −


Live Demo


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

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