Multiple expressions (E, F, G)

Description and Syntax

$('E, F, G')

selects all elements matched by any of the selector expressions E, F, or G.

Examples

  • $('code, em, strong') selects all <code>, <em>, and <strong> elements.
  • $('p strong, .myclass') selects all <strong> elements that are descendants of a <p> element, as well as all elements that have a class of myclass

<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!--from  www  .  java2s.  co  m-->
              $("div,span,p.myClass").css("color","red");
        });
    </script>
  </head>
  <body>
    <body>
        <div>div</div>
        <p class="myClass">p class="myClass"</p>
        <p class="notMyClass">p class="notMyClass"</p>
        <span>span</span>


    </body>
</html>

Click to view the demo

The code above generates the following result.

Multiple expressions (E, F, G)