Easy Tutorial
❮ Event Live Traversing Filter ❯

jQuery delegate() Method

jQuery Event Methods

Example

Change the background color of all <p> elements when a <p> element inside a <div> element is clicked:


Definition and Usage

The delegate() method adds one or more event handlers for specified elements that are children of selected elements, and specifies the function to run when these events occur.

The event handlers added using the delegate() method apply to current or future elements (such as new elements created by a script).

Since jQuery version 1.7, the on() method is the preferred way to attach event handlers to selected elements.


Syntax

Parameter Description
childSelector Required. Specifies one or more child elements to add the event handler(s) to.
event Required. Specifies one or more events to add to the elements. <br> <br>Multiple event values are separated by spaces. Must be valid events.
data Optional. Specifies additional data to pass to the function.
function Required. Specifies the function to run when the event occurs.

More Examples

Add Event Handler to Future Elements

Pass Data to the Function


jQuery Event Methods

❮ Event Live Traversing Filter ❯