Javascript Event How to - Click to remove all event handlers and data








Question

We would like to know how to click to remove all event handlers and data.

Answer


<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){<!-- w w w . j a  v  a 2s  . c  om-->
                  $("p").click(function () {
                      $(this).empty();
                  });
         });
    </script>
  </head>
  <body>
      <p>World</p>
      <div>Replaced!</div>
   </body>
</html>

The code above is rendered as follows: