on() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:on

Description

The on() method attaches one or more event handlers for the selected elements and future added child elements.

Syntax

Parameter RequireDescription
event Required.one or more event(s) or namespaces to attach to the selected elements.
childSelector Optional. the event handler should only be attached to the specified child elements
data Optional. additional data to pass along to the function
function Required. the function to run when the event occurs
map Optional.an event map ({event:function, event:function, ...}) to attach to the selected elements to run when the events occur

The following code shows how to Attach a click event to the <p> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("p").on("click dblclick", function(){
        $(this).animate({fontSize: "+=6px"});
    });//www .j a  va2  s.c  o m
});
</script>
</head>
<body>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<p>Click and double click any p element to increase its text size.</p>

</body>
</html>

Related Tutorials