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); });
<!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>