Binds a handler to a particular event (like click) for each matched element. The event handler is passed an event object that you can use to prevent default behaviour. To stop both default action and event bubbling, your handler has to return false.
In most cases, you can define your event handlers as anonymous functions (see first example). In cases where that is not possible, you can pass additional data as the second parameter (and the handler function as the third), see second example.
Calling bind with an event type of "unload" will automatically use the one method instead of bind to prevent memory leaks.
Example:
<div class="codeview">
$("p").bind("click", function(){
alert( $(this).text() );
});
HTML:
<p>Hello</p>
Result:
alert("Hello")
</div>
No comments:
Post a Comment