Skip to main content

Explain event binding with .on() and .off().

Mid JQuery
Quick Answer .on(event, selector, handler) attaches a handler - selector enables delegation for dynamic elements. .off(event, selector, handler) removes a specific handler. Omit the handler to remove all handlers for the event. .on() replaces all deprecated methods (.bind, .live, .delegate). Always pair .on with .off in cleanup to prevent memory leaks.

Answer

.on() binds events to static and dynamic elements.
.off() removes event handlers.
Supports namespaced events: $('#id').on('click.myNs', handler)
Helps modular event management.
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice