Table of Contents
The most important aspects that deals with events via jQuery is blind() method. From the name itself, it is used to attach one or more events on a set of elements. It is a method specifies a function to run while the event occurs. This method will be used together with other events.
Syntax for bind() method
$(selector).bind(event,data,function,map)
The parameters of bind() methods are event, data, function and map. Here, event and data parameters are mandatory.
- Event – specifies one or several events to attach to the elements. You can add many events separated by space.
- Data – used to mention added data to pass along to the function. It is an optional parameter.
- Function – It is a mandatory parameter, used to executes the function to run when the event occurs.
- Map – specifies an event map that contains one or more events attached to the element.
Example of jquery bind()
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").bind("click", function(){
alert("Given paragraph was clicked.");
});
});
</script>
</head>
<body>
<p>Click me!</p>
</body>
</html>