.unbind() accepts a string describing the event type to unbind.

Syntax

.unbind([eventType[, handler]])
eventType: A string containing a JavaScript event type such as click or submit. handler: The function that is to be no longer executed
.unbind(event)
event: A JavaScript event object as passed to an event handler

Return value

The jQuery object, for chaining purposes.

Description

Remove a previously-attached event handler from the elements.

Any handler that has been attached with .bind() can be removed with .unbind(). In the simplest case with no arguments, .unbind() removes all handlers attached to the elements.

$('#foo').unbind();

This version removes the handlers regardless of type.

To be more precise, we can pass an event type.

$('#foo').unbind('click');

By specifying the click event type, only handlers for that event type will be unbound.

The following code remove action handler by function

var handler = function() {
 alert('The quick brown fox jumps over the lazy dog.');
};
$('#foo').bind('click', handler);
$('#foo').unbind('click', handler);

To unbind a handler, we need a reference to that function.

$("selectorHere").unbind("mouseover");

This removes all events of type mouseover from the selected elements.

Using namespaces

We can namespace the events and use this capability to narrow the scope of our unbinding actions.

namespaces are defined by using a period (.) character when binding a handler.

$('#foo').bind('click.myEvents', handler);

When a handler is bound in this fashion, we can still unbind it the normal way.

$('#foo').unbind('click');

To avoid affecting other handlers, we can be more specific.

$('#foo').unbind('click.myEvents');

If multiple namespaced handlers are bound, we can unbind them at once.

$('#foo').unbind('click.myEvents.yourEvents');

This syntax is similar to that used for CSS class selectors; they are not hierarchical. This method call is thus the same as the following:

$('#foo').unbind('click.yourEvents.myEvents');

We can also unbind all of the handlers in a namespace, regardless of event type.

$('#foo').unbind('.myEvents');

Examples

Unbind click event

 
<html>
  <head>
    <script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
               function aClick() {
                  $("div").show().fadeOut("slow");
               }
               $("div").click(function () {
                  $("div").unbind('click', aClick).text("Does nothing...");
               });
        });
    </script>
  </head>
  <body>
    <body>
       <div><h1>header 1</h1></div>
    </body>
</html>
  
Click to view the demo

Unbind all events from div

 
<html>
  <head>
    <script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
               $("div").unbind()
        });
    </script>
  </head>
  <body>
    <body>
       <div><h1>header 1</h1></div>
    </body>
</html>
  
Click to view the demo

Without any arguments, all bound events are removed.

 
<html>
  <head>
    <script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.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>
    <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
Home 
  JavaScript Book 
    jQuery  

Event:
  1. jQuery Event
  2. jQuery's methods for event
  3. Event object
  4. event.keycode
  5. event.clientX/clientY
  6. event.pageX/pageY: click event coordinates
  7. event.preventDefault()
  8. event.stopPropagation(): Stop only an event from bubbling by using the stopPropagation method.
  9. event.target.tagName
  10. event.which:check key code
  11. return false to Cancel a default action and prevent it from bubbling up
  12. bind
  13. .blur()
  14. .change()
  15. .click()
  16. .error()
  17. .dblclick()
  18. .delegate()
  19. die:Removes a bound live event
  20. .focus()
  21. .hover()
  22. keydown() event
  23. .keypress()
  24. keyup event and check the key code
  25. .live()
  26. .load()
  27. mousedown() event
  28. mouseenter() event
  29. mouseleave
  30. mousemove()
  31. mouseover() event
  32. mouseout
  33. mouseup() event
  34. .off() removes events
  35. .on() replaces the functionality of all the event methods.
  36. .one() method executes handler only once.
  37. .ready()
  38. .resize()
  39. .scroll()
  40. .select()
  41. .submit()
  42. .toggle()
  43. .trigger()
  44. .triggerHandler()
  45. .unbind() accepts a string describing the event type to unbind.
  46. .undelegate() removes the binding
  47. .unload()
  48. use bind/trigger to create custom event