Reputation: 48943
What does bind and unbind mean in jquery in idiot slow learner terms?
Upvotes: 7
Views: 6657
Reputation: 187050
In simple terms: for binding and unbinding event handlers to elements.
$("#divElement").bind('click', functionName);
binds a click event handler to the element with id divElement
$("#divElement").unbind('click', functionName);
unbinds a click event handler to the element with id divElement
Edit:
Bind also allows you to bind a handler to one or more events.
$("#divElement").bind("click dblclick mouseout", function(){ // your code });
Update:
As of jQuery 1.7, the .on() and .off() methods are preferred to attach and remove event handlers on elements.
Upvotes: 7
Reputation: 338228
In three sentences:
An event is a signal that is visible in your program - a key press, for example.
A handler is a function that is geared towards reacting to a certain event.
Binding associates a handler with an event, unbinding does the opposite.
Upvotes: 3
Reputation: 77181
Bind attaches a piece of code to be run to a given HTML element (which is run on the supplied event). unbind removes it.
Upvotes: 0
Reputation: 38860
Binding: coupling an handler to an element(s), that will run when an event occurs on said element(s). Depending on what kind of event you want to handle you'd use different functions like click(function)
(alt: bind('click', function)
or focus(function)
(alt: bind('focus', function)
.
Unbinding: de-coupling of an handler from an element(s), so that when an event occurs the handler function will no longer run. Unbinding is always the same; unbind('click', function)
to unbind a certain handler, unbind('click')
to unbind ALL click handlers, and unbind()
to unbind ALL handlers. You can substitute click
for other types of events of course.
Upvotes: 7