jQuery Selector How to - Select the element with the class "myClass"








Question

We would like to know how to select the element with the class "myClass".

Answer


<!--from   ww  w . java2  s . c  o m-->
<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").css("border","3px solid red");
        });
    </script>
  </head>
  <body>
      <div class="myClass">div class="myClass"</div>
      <span class="myClass">span class="myClass"</span>
  </body>
</html>

The code above is rendered as follows: