Add click event to document : closest « jQuery « JavaScript Tutorial






<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
          $(document).bind("click", function (e) {
               $(e.target).closest("span").text("asdf");
          });
        });
    </script>
  </head>
  <body>
    <body>
         <div><span>span</span><span>span</span><span>span</span></div>
  </body>
</html>








30.26.closest
30.26.1.Add click event to document
30.26.2.Get closest tag