API Docs for:
Show:

EventDelegation Class

Defined in: latest/events.js:142
Module: DOM
Parent Module: JSFramework

Event delegation - Attach an event handler to a container element to handle events for inner elements. This has several advantages, including improved performance when a lot of elements are involved (as less event handlers are attached), and not having to attach event handlers to AJAX-loaded content.

Item Index

Methods

Properties

Methods

add

(
  • containerEl
  • type
  • tagName
  • className
  • fn
)
chainable

Attach a handler to all tagNames with a class of className, by attaching the event listener to containerEl. Works for both current elements, and new elements added in the future.

Parameters:

  • containerEl Element

    Container element to add event listener to

  • type String

    Type of event listener (eg. "click")

  • tagName String

    Tag name to add events to (eg. "a")

  • className String

    Class name to add events to, or null for none

  • fn Function

    Event handler function

handle

(
  • e
)
private

Handle a delegated event

Parameters:

  • e Event

    Event data

Properties

delegates

Object private

The current delegates