jQuery bind() Method (original) (raw)
Last Updated : 22 Apr, 2024
**The **jQuery bind() method is used to attach one or more event handlers for selected elements. This method specifies a function to run when an event occurs.
**Syntax
$(selector).bind(event, data, function);
**Parameters
It accepts three parameters that are described below:
- **event: This is an event type that is passed to the selected elements.
- **data: This is the data that can be shown over the selected elements.
- **function: This is the function that is performed by the selected elements.
**Note: This method has been deprecated.
**Example 1: In this example, "click" events are attached to the given paragraph using bind() method.
HTML `
<script>
$(document).ready(function () {
$(".paragraph").bind("click", function () {
alert("Paragraph is Clicked");
});
});
</script>
<style>
.paragraph {
width: 190px;
margin: auto;
padding: 20px 40px;
border: 1px solid black;
}
</style>
Welcome to GeeksforGeeks
`
**Output:
**Example 2: In this example, the "click" event is added but this time data is also passed to the **bind() method.
HTML `
<script>
function handlerName(e) {
alert(e.data.msg);
}
$(document).ready(function () {
$(".paragraph").bind("click", {
msg: "Paragraph is Clicked."
}, handlerName)
});
</script>
<style>
.paragraph {
width: 190px;
margin: auto;
padding: 20px 40px;
border: 1px solid black;
}
</style>
Welcome to GeeksforGeeks
`
**Output: