Hi Reader's,
Welcome to FindNerd, in this blog I will guide you to use event.data Property in Jquery.
Basically event.data property is used when the current executing handler is bound. so we can say that it is an optional object of data passed to an event method when the current executing handler is bound.
syntax of event.data property
event.data
event is a required parameter here.
you can see below example:
<!DOCTYPE html>
<html>
<head>
<!-- here add jquery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
//call paragraph to event
$("p").each(function(i){
//call event.data property on click
$(this).on("click", {x:i}, function(event){
//alert massage
alert("The value is " + $(this).index() + ". test paragraph has data value is: " + event.data.x);
});
});
});
</script>
</head>
<body>
<!-- Click on each p element to return the data passed with the on() method -->
<p>Tset paragraph.</p>
<p>Another tset paragraph.</p>
<p>Another tset paragraph.</p>
</body>
</html>
0 Comment(s)