Home >>jQuery Tutorial >jQuery bind() Events
jQuery bind() Events in jQuery is used to attach the selected elements to one or more event handlers, and specifies a function to run when the event occurs.
jQuery was deprecated Events in version 3.0. you can use the on() method instead.
Syntax:
$(selector).bind(event,data,function,map)
Parameter | Description |
---|---|
event | It is a required parameter and is used to Specifies one or ultiple events to attach to the elements. |
data | It is optional and is used to Specifies additional data to pass to the function |
function | It is a required parameter and is used to Specifies the function to run when the event occurs |
map | This parameter is used to Specifies an event map ({event:function, event:function, ...}) containing one or multiple events to attach to the elements. |
Here is an Example of jQuery bind() Method:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"<</script>
<script>
$(document).ready(function(){
$(".txt").bind("click", function(){
alert("clicked the paragraph :)");
});
});
</script>
</head>
<body>
<p class="txt"<Click here!</p>
</body>
</html>
Click here!