Unbind an event handler function in jQuery

Description

The following code shows how to unbind an event handler function.

Example


<!--from www . j  av  a2s .  c  om-->
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
function aClick() {
alert("action");
}
$("#bind").click(function () {
$("#myButton").click(aClick).text("Binded");
});
$("#unbind").click(function () {
$("#myButton").unbind('click', aClick).text("Not Binded");
});
});
</script>

</head>
<body>
<button id="myButton">Not Binded</button>
<button id="bind">Bind Click</button>
<button id="unbind">Unbind Click</button>
</body>
</html>

Click to view the demo

The code above generates the following result.

Unbind an event handler function in jQuery
Home »
  Javascript Tutorial »
    jQuery »
      jQuery Event
...
Handle form select change event in jQuery
Handle input text element key type event in...
Handle the first time click event on div ta...
Handler div element mouse hover event in jQ...
Hover to fade in and out in jQuery
Hover to hide tag in jQuery
Listen to keydown event in jQuery
Listen to keyup event for input element in ...
Listen to load event in jQuery
Listen to mouse down event in jQuery
Listen to mouse enter event in jQuery
Listen to mouse leave event in jQuery
Listen to mouse out event in jQuery
Listen to mouse over event in jQuery
Listen to mouse up event in jQuery
Listen to scroll event in jQuery
Listen to the escape key in jQuery
Listen to the unload event in jQuery
Remove click event from div tag in jQuery
Return false to cancel event and prevent it...
Set focus for an input text element in jQue...
Set focus to text box in jQuery
Set value in case of focus event in jQuery
Show the typed value for keyup event in jQu...
Trigger a custom event in jQuery
Trigger click event in jQuery
Trigger click handler in jQuery
Trigger focus event handler in jQuery
Trigger mouse over event in jQuery
Trigger slide up with double click in jQuer...
Trigger the change event in jQuery
Unbind all events from div in jQuery
Unbind all live events from all paragraphs ...
Unbind an event handler function in jQuery
Unbind click event in jQuery
Use blur event to change the style for the ...
Use event.which to check the key code in ke...
Use hover action to add and remove class in...
...