.bind() (since 1.0, deprecated 3.0) attaches a handler to one or more events on every matched element. It only supports direct binding — no delegation. New code should use .on() (since 1.7), which accepts the same arguments plus a delegation selector.
Syntax
Start with these common calls. Keep them short and readable.
Attach handler for one or more space-separated event types
.bind(eventType, eventData, handler)
Same, with data available as event.data (since 1.4.3)
.bind(eventType, false)
Shorthand for a handler that returns false (since 1.4.3)
.bind(events)
Object map of { type: handler } pairs (since 1.4)
.bind("type.namespace", handler)
Tag the binding so it can be removed as a group later
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
eventType
A string with one or more event types separated by spaces, optionally with namespaces: "click", "keydown.myPlugin".
eventData
Optional object passed to the handler as event.data. Read when the event fires, not when you bind.
handler
function(eventObject) that runs each time the event fires. Inside it, this is the DOM element.
events
An object where each key is an event type (namespaces allowed) and each value is a handler function.
false
Pass false instead of a function to prevent the default action and stop bubbling.
Return Value
Return Value
Description
jQuery object
The original collection, so you can chain more methods such as .addClass() or .on().
jQuery Examples
Example 1 — Basic .bind() and the .on() Equivalent
Attach a click handler the legacy way, then see the one-word migration.
jQuery
// Legacy
$("#foo").bind("click", function () {
$("#log").text("clicked via .bind()");
});
// Modern replacement
$("#foo").on("click", function () {
$("#log").text("clicked via .on()");
});
Before removal → both handlers run
After .unbind(".myEvents") → only "other click" remains
How It Works
Namespace.click.myEvents is still a click handler, tagged for later cleanup.
Group remove..unbind(".myEvents") removes every handler in that namespace.
Prefer .off(). It removes handlers from both .bind() and .on().
Frequently Asked Questions
.bind() attaches an event handler directly to each matched element. You can pass an event type (or several, space-separated), optional eventData, and a handler function, or an object that maps event types to handlers.
Yes. .bind() has been deprecated since jQuery 3.0. It still works in 3.x, but it only supports direct binding. Use .on() (available since 1.7) for all new code.
Replace the method name and keep the arguments: .bind("click", fn) becomes .on("click", fn), .bind("click", data, fn) becomes .on("click", data, fn), and .bind({ click: fn }) becomes .on({ click: fn }). Namespaces such as click.myPlugin work the same way.
.bind() only attaches handlers directly to the selected elements. .on() does the same, and also supports delegated handlers via an optional selector argument, so it works for elements added to the page later.
Use .unbind() for legacy code or .off() for modern code. Both accept an event type, a handler reference, or a namespace such as .off(".myPlugin"). .off() works for handlers added with .bind() and .on().
It is shorthand for a handler that calls event.preventDefault() and event.stopPropagation(). The modern equivalent is .on("click", false). Use .off("click") to remove it.