Home >>jQuery Tutorial >jQuery event.data Property
jQuery event.data property in jQuery includes the optional data passed to an event method when bound by the current executing handler.
Syntax:event.data
Parameter | Description |
---|---|
event | It is a required parameter is used to the event parameter comes from the event binding function |
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".txt1").each(function(i){
$(this).on("click", {x:i}, function(event){
alert("The " + $(this).index() + ". paragraph has contains data: " + event.data.x);
});
});
});
</script>
</head>
<body>
<div style="color:dodgerblue">Click on each p element it returns the data passed</div>
<p class="txt1">This is First paragraph.</p>
<p class="txt1">This is Second paragraph.</p>
<p class="txt1">This is Third paragraph.</p>
</body>
</html>
This is First paragraph.
This is Second paragraph.
This is Third paragraph.