Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>Example</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
  body {
    font-family: sans-serif;
  }
  .test {
    background-color: yellow;
  }
</style>
</head>
<body>
  <p>The "static" div below exists before we hook up our
  event handlers; the "dynamic" one is adding after.
  Click each of them to see which handlers fire.</p>
  <table id="theTable">
    <tbody>
      <tr><td><div class='test' style='width:164px; height:22px; margin:0 auto; z-index:1000'>static</div></td></tr>
      <tr><td id="target"></td></tr>
    </tbody>
  </table>
</body>
</html>
 
jQuery(function($) {
  
  // Note that the div doesn't exist yet, so this won't
  // hook it up
  $(".test").click(function() {
    display("Direct click handled on " +
            this.innerHTML
           );
  });
  
  // This form uses event delegation. Note that the div
  // still doesn't exist.
  $("#theTable").delegate(".test", "click", function() {
    alert("Bruh");
    display("Delegated click handled on " +
            this.innerHTML
           );
  });
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers