jQuery delegate | Using delegate of jQuery for child elements event handlers

jQuery delegate() method

The delegate() method of jQuery is almost same like live() method, except it attaches event handlers to child elements of specified selector. For example if Div is a parent selector specified in delegate method,

event handlers to child paragraphs <p>, current or in future, can be attached by using delegate method along with function to perform desired actions. Unlike live() event handlers will be attached to child element(s) only.

Syntax of delegate method


For example

$(“div”).delegate(“p”,”click”, function_to_execute)

If multiple events need to be attached it has to separate by a space.

$(“div”).delegate(“p”,”click mouseleave”, function_to_execute)

Example of using delegate() method

Experience this example online

From 1.7 version of jQuery library the preferred method is on() method.

Was this article helpful?

Related Articles

Leave A Comment?