How to use bind() Method in jQuery
This article describe about bind() Method in jQuery.
jQuery Event Methods
The jQuery event methods are take effect when the user interacts with the browser to register behaviors, and manipulate those registered behaviors furthers.
jQuery event methods trigger, or bind function to an event.
Trigger example:
$("button").click() - Trigger generate on the click event of button element.
Binding example:
$("button").click(function(){$("img").hide()}) - This method bind the function on click event.
jQuery bind() example:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("button").bind("click", function () {
$("p").slideToggle();
});
});
</script>
</head>
<body>
<p>This is my first paragraph.</p>
<button>Click me!</button>
</body>
</html>
|
Output
After click on the button output look like
Note: Here after click on the button the paragraph <p> hide.
Bind Events and Functions to Elements
It is specifies that to attach one or more event handlers to selected elements, and also function to run when event occurs.
Syntax
$(selector).bind(event,data,function)
|
Alternate syntax
$(selector).bind({event:function, event:function, ...})
|
You may also want to read these related articles Click here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here