Bind() method:
Bind method is used to attach events to selected elements and also used to specify a function when the event occurs.
Syntax:
$(selector).bind(event,data,function,map)
Example:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").bind("click", function(){
alert("Hello");
});
});
</script>
</head>
<body>
<p>Bind Method Example</p>
<button>Click to see message</button>
</body>
</html>
In the above example a method has been attached to button using bind() method. When user will click on button a alert will appear.
You can check above example output here: https://jsfiddle.net/0dpafkkp/
0 Comment(s)