Friday, May 25, 2012

jQuery .live() and .die()

Similar to .bind() and .unbind(), .die() remove the handler set by .live().

<!doctype html>
<head>
 <title>Mobile-Web-App: jQuery .live() and .die()</title>
 <meta charset="utf-8">
 <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
 <script>
  $(document).ready(function(){
  
   //"#clickme" not yet existed
   $("#clickme").live('click', (function(event){
    alert("'clickme' Clicked! and die.()");
    $("#clickme").die('click');
   }));
    
   $("<p id='clickme'>Click Me (accept one time only)</p>").appendTo("#addhere");
  });
 </script>
 
</head>
<body>
<p><b>Mobile-Web-App: jQuery .live() and .die()</b></P>
<div id="addhere"></div>
</body>
</html>


.live() and .die()


No comments:

Post a Comment