The on() method is used to attach one or more event handlers for the selected elements. It is designed to replace both the .bind() and .delegate() event handlers.
Syntax:
$(selector).on(event,childSelector,data,function,map)
where
PARAMETER |
DESCRIPTION |
Required/Optional |
event |
Can attach one or more events to the selected elements separated with spaces. |
Required |
childSelector |
It determines that an event handler should attached to the specified child elements |
Optional |
data |
For additional data |
Optional |
function |
Specifies the function to run at the time when an event occurs |
Required |
map |
Use to map one or more events to the selected elements and to run the function when events occur |
Optional |
Example:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function()
{
$("p").on("click", function()
{
$(this).css("background-color", "#cccccc");
});
});
</script>
</head>
<body>
0 Comment(s)