Home  >  jQuery

Example of .bind() in jQuery

February 21, 2013
.bind() in jQuery can bind a function with an event. Let’s suppose we have an event click, we can bind a function that when we click, a message should be displayed. Then .bind() will work as
$("span").bind("click", function(event){
var str = "U have clicked!";
$("p").text(str);
});
So here click event has been bound with a functionality in which “U Have Clicked” will be printed. Find a example of .bind() in jQuery.
<!DOCTYPE html>
<html>
<head>
<style>
p {background-color:green}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<span>Click or DoubleClick To Test</span>
<p></p>
<script>
$("span").bind("click", function(event){
var str = "U have clicked!";
$("p").text(str);
});
$("span").bind("dblclick", function(event){
var str = "U have Double clicked!";
$("p").text(str);
});
</script>
</body>
</html>
 
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us