The snippet library.
Small, practical examples. Search by task or narrow things down below.
Attach configuration when registering a handler
jQuery: event.data carries the registration-time data object.
jQuery✓ Tested
Pass values through a custom event
jQuery: trigger passes its extra argument array after the event object.
jQuery✓ Tested
Prevent navigation from a handled link
jQuery: preventDefault cancels the browser action without cancelling event bubbling.
jQuery✓ Tested
Read a handler result without event bubbling
jQuery: triggerHandler invokes the first matched element’s handlers without native default behavior.
jQuery✓ Tested
Read a selection when its change event fires
jQuery: A change handler observes the current selected value.
jQuery✓ Tested
Remove one handler without removing others
jQuery: Pass the original function reference to off.
jQuery✓ Tested
Remove related events by namespace
jQuery: Namespaced events let a feature clean up its own handlers.
jQuery✓ Tested
Respond to the Enter key
jQuery: Use the event key rather than deprecated numeric key codes.
jQuery✓ Tested
Stop a child event from reaching its parent
jQuery: stopPropagation leaves other handlers on the same element intact.
jQuery✓ Tested
Validate a field when focus leaves it
jQuery: focusout bubbles and can support delegated form validation.
jQuery✓ Tested