jQuery Multiple expressions selector

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(){<!--   w w  w. j a v  a 2  s.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





















Home »
  jQuery »
    jQuery Tutorial »




Basics
Selector
DOM
Event
Effect
Utilities