Usage and distinction resolution of bind live delegate and one methods in jQuery

  • 2020-03-30 01:08:27
  • OfStack

The bind() method is used to attach a handler to the event of each matched element and return the jQuery object.

Bind (eventType [, evnetData], Handler (eventObject))

Where, the parameter eventType is a string containing one or more javaScript event types, such as click, submit, or the name of a custom event. EventData is of type Map and gives the data to be passed to the event handler. The handler specifies the function to be executed when the event is triggered. EventObject represents the eventObject.

The.bind() method attaches the event handler to the eventType event for each element in the matching set of elements and can pass the data to the event handler if needed.

The live() method attaches an event handler to the specified event for all elements that match the current selector (including existing or future additions) and returns the jQuery object.

Live (eventType, eventData, handler)

Where, parameter eventType is a string containing one or more javaScript event types, such as click, keydown, or the name of a custom event, and eventData is an optional parameter of Map type, giving the data to be passed to the event handler, which is added in jQuery1.4. Handler is a function that is executed when the event is triggered

The.live() method appends the event handler to each eventType event with a matching element (both existing and future) and, if necessary, can pass the data to the event handler using participating eventData.

. Live () method is essential. The bind () method of a deformation, which can attach an event handler to the element ・ , when calling. The bind (), jQuery object matching element will be attached on the event handler, but add element will not be added after the event handler, therefore, also need to call again for these elements. The bind () method.

The.one() method attaches the event handler to the specified event of the matching element and returns the jQuery object. The attached event handler can only be executed once at most.

One (eventType, eventData, handler (eventObject))

Where, the parameter eventType is a string containing one or more javaScript event types, such as click, submit, or the name of a custom event. EventData is of type Map and gives the data to be passed to the event handler. The handler specifies the function to be executed when the event is triggered. EventObject represents the eventObject.

The.one() method is similar to.bind() except that the event handler that USES the.one() binding is automatically unbound after one execution.

The.delegate() method attaches a handler to one or more events that match all the elements of the selector (existing or future) based on a specific set of root elements.

Delegate (selector, eventType [, eventData], handler)

The argument selector is a selector that filters the elements that trigger the event. EventType is a string that specifies one or more JavaScript event types (multiple events separated by Spaces), such as click,keydown, or custom event names. EventData is a mapping type that represents the data to be passed to the event handler. Handler represents the function that executes when the event is triggered.

.delegate() is similar to.live() in that it delegates the binding of each event to a specified DOM element.


Related articles: