Home >>jQuery Tutorial >jQuery on() Method

jQuery on() Method

jQuery on() Method

jQuery on() method in jQuery is used to add one or multiple event handlers for the selected elements and child elements.

Syntax:
$(selector).on(event,childSelector,data,function,map)

Parameter Values

Parameter Description
event It is a required parameter and is used to specifies one or multiple event to attach to the selected elements.
childSelector It is an Optional parameter and used to specifies that the event handler should only be add to the specified child elements
data It is an optional parameter and used to specifies additional data to pass along to the function
function It is a required parameter and used to specifies the function to run when the event occurs
map It is used to specifies an event map which containing one or multiple event to add to the selected elements
Here is an Example of jQuery on() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".txt").on("click", function(){
alert(" paragraph was clicked.");
});
});
</script>
</head>
<body>
<p class="txt">Click Me !</p>
</body>
</html>

Output:

Click Me !