VOOZH about

URL: https://www.geeksforgeeks.org/jquery/jquery-on-method/

⇱ jQuery on() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

jQuery on() Method

Last Updated : 10 Jul, 2023

The jQueryon() is an inbuilt method that is used to attach one or more event handlers for the selected elements and child elements in the DOM tree. The DOM (Document Object Model) is a World Wide Web Consortium standard. This method defines accessing elements in the DOM tree. 

Syntax:

$(selector).on(event, childSelector, data, function)

Parameter: It accepts some parameters which are specified below-

  • event: This specifies the events that are attached to the selected element.
  • childSelector: This is optional and this specifies the specific child to which the given event handler can be used.
  • data: This is optional and this specifies additional data to be passed along with the function.
  • function: This specifies the function to run when the event occurs.

Return Value: This returns all the event handlers that are attached to the selected element. 

Example 1: In the code below child specifier and data is not passed. 

Output:

👁 Image

Example 2: In the below code data and message both are being passed to the function. 

Output:

👁 Image
Comment
Article Tags:

Explore