16 Feb jQuery bind() method
Definition
Use the bind() method in jQuery to attach event handlers for the elements matched. On event occurrence, it allows a function to run, for example, fire an alert box on click.
Note: bind() method is now deprecated. For the same results, use the jQuery on() method.
Syntax
The following is the syntax,
$(selector).bind(ev,data,func)
The following are the parameters used by the bind() method,
- ev: Indicate event(s).
- data: Pass additional data to the event handled. This parameter is optional.
- func: When event occur, this functions runs.
Example
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").bind("click", function(){
alert("You clicked on me! Welcome to Studyopedia");
});
});
</script>
</head>
<body>
<h2>Learning jQuery</h2>
<p>I am a text. Click on me!</p>
</body>
</html>
The following is the output,

Click on the text, and the following alert box will be visible,

No Comments