<?xml version='1.0' encoding='ISO-8859-1'?>
<?xml-stylesheet type='text/xsl' href='docs.xsl'?>
<docs>
<method cat='Events' type='jQuery' short='Binds a handler to a particular event (like click) for each matched element.' name='bind'>
<desc>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.</desc>
<params type='String' name='type'>
<desc>An event type</desc>
</params>
<params type='Object' name='data'>
<desc>(optional) Additional data passed to the event handler as event.data</desc>
</params>
<params type='Function' name='fn'>
<desc>A function to bind to the event on each of the set of matched elements</desc>
</params>
<examples>
<code>$("p").bind("click", function(){
  alert( $(this).text() );
});</code>
<result>alert("Hello")</result>
<before>&lt;p&gt;Hello&lt;/p&gt;</before>
</examples>
<examples>
<desc>Pass some additional data to the event handler.</desc>
<code>function handler(event) {
  alert(event.data.foo);
}
$("p").bind("click", {foo: "bar"}, handler)</code>
<result>alert("bar")</result>
</examples>
<examples>
<desc>Cancel a default action and prevent it from bubbling by returning false
from your function.</desc>
<code>$("form").bind("submit", function() { return false; })</code>
</examples>
<examples>
<desc>Cancel only the default action by using the preventDefault method.</desc>
<code>$("form").bind("submit", function(event){
  event.preventDefault();
});</code>
</examples>
<examples>
<desc>Stop only an event from bubbling by using the stopPropagation method.</desc>
<code>$("form").bind("submit", function(event){
  event.stopPropagation();
});</code>
</examples>
</method></docs>
