bind() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:bind

Description

The bind() method was deprecated in version 3.0. Use the on() method instead.

The bind() method attaches one or more event handlers for selected elements.

Syntax

$(selector).bind(event,data,function,map);
Parameter Require Description
event Required. one or more events to attach to the elements.
data Optional. additional data to pass along to the function
function Required.the function to run when the event occurs
map Optional. event map ({event:function, event:function, ...}) to attach to the elements

The following code shows how to Attach a click event to the <p> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("p").bind("click", function(){
        console.log("The paragraph was clicked.");
    });//from  w w w  . j  a v a 2  s .c  om
});
</script>
</head>
<body>

<p>Click me!</p>

</body>
</html>

Related Tutorials