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:

**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:

jQuery-bind-method

**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:

jQuery-bind-method