jQuery Examples - $("p strong, .myclass")



Description

"$("p strong, .myclass")" Selects all elements matched by <strong> that are descendants of an element matched by <p> as well as all elements that have a class of myclass.

Syntax

Here is the simple syntax to use this selector −

$("parent-element child-element, .class")

Parameters

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

  • element − element type of container element

  • child-element − element type of child element

  • class − style class of child element

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() {
            /*  Selects all elements matched by <ul> that follow a sibling element matched by <
            p>.*/
            $("p strong, .myclass").css("background-color", "yellow");
         });
      </script>
   </head>
	
   <body>
      <p>With <strong>Coding Ground</strong> we bring an Online Lab where you 
         can create your programs in more than <span class="myclass">80 programming languages
         </span>, compile, execute and share them over the web, which provides you 
         remarkable learning experience at a cost of just an internet connection!</p>
   </body>
</html>

This will produce following result −

jqueryexamples_selectors.htm
Advertisements