jQuery Examples - $("#container p")



Description

"$("#container p")" Selects all elements matched by <p> that are descendants of an element that has an id of container.

Syntax

Here is the simple syntax to use this selector −

$("#tagname child-element")

Parameters

Here is the description of all the parameters used by this selector −

  • #tagname − Id of the container

  • child-element − descendent of element that has an id of container.

Returns

Like any other jQuery selector, this selector also returns an array filled with the found elements.

Example

<html>
   <head>
      <title>The Selector Example</title>
      <script type = "text/javascript" 
         src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">          
      </script>
      <script type = "text/javascript" language = "javascript">
         $(document).ready(function() {
            /* Select link with an id of first and a class of big.*/
            $("#sizeDiv p").css("background-color", "yellow");
         });
      </script>
   </head>

   <body>
      <div id = "sizeDiv">
         <p id = "first" class="big">Big</p>
         <a id = "second" class="big" href="#">Medium</a>
         <p id = "third" class="big">Small</p>
      </div>
      
   </body>
</html>

This will produce following result −

jqueryexamples_selectors.htm
Advertisements