jQuery Selector How to - Select nested classes








Question

We would like to know how to select nested classes.

Answer


<!--from w  w w .  j  a v a  2  s  .c om-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
      $(document).ready(function(){
            $(".myClass.myOtherClass").css("border","1px solid red");
      });
    </script>
  </head>
  <body>
      <div class="notMe">div </div>
      <div class="myClass">div</div>
      <span class="myClass myOtherClass">span</span>

  </body>
</html>

The code above is rendered as follows: