is(expr) : is « jQuery « JavaScript Tutorial






<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
                 
                   $("div").one('click', function () {
                      if ($(this).is(":first-child")) {
                        $("p").text(":first-child");
                      } else if ($(this).is(".blue,.red")) {
                        $("p").text("It's a blue or red div.");
                      } else if ($(this).is(":contains('asdf')")) {
                        $("p").text("It's asdf!");
                      } else {
                        $("p").html("It's nothing <em>special</em>.");
                      }
                    });
                    

        });
    </script>
 <style>

  div.middle { color: red; }

  
</style>
  </head>
  <body>
    <body>
          <div>asdf</div>
          <div class="blue">asdf</div>
          <div class="red">asdf</div>
          <div><span>asdf</span>asdf</div>
          <div class="blue">asdf</div>
          <p>asdf</p>
    </body>
</html>








30.59.is
30.59.1.Traversing IS
30.59.2.Is it class
30.59.3.is(expr)
30.59.4.is() can be used inside an event handler.