jQuery Method How to - Use unbind() method to remove all event








Question

We would like to know how to use unbind() method to remove all event.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.6.2.js'></script>
<script type='text/javascript'>
function testJQueryClick(){<!-- w  w  w  . java2s  .com-->
     $('#button2').unbind().click(function(){ 
         console.log ('Debug'); 
         return false; 
     });
}

</script>
</head>
<body>
  <input type="button" id="button1" value="Button 1" onclick="testJQueryClick(); return false" />
  <input type="button" id="button2" id="button2" value="Button 2" />
</body>
</html>

The code above is rendered as follows: