jQuery on() with Examples

jQueryWeb DevelopmentFront End Technology

The on() method in jQuery is used to attach event handlers to elements.


The syntax is as follows −


Above, the event parameter specifies one or more events or namespaces to attach to the selected element(s), childSelector is used to specify that the event handler should be attached to the specified child elements. The function parameter is the function to run when the event triggers, whereas the map parameter is the event map.


Let us now see an example to implement the jQuery on() method 

 Live Demo

<!DOCTYPE html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
         $("p").css("font-size", "1.5em");
<h2>Demo Heading</h2>
<p>Click below button to change the font size.</p>


This will produce the following output −

Click the “Change” button to update the font size −

Updated on 30-Dec-2019 09:43:07