jQuery
New Wave Javascript


This code is part of the the jQuery Base module.

Events

bind(String,Function)

Attaches the specified function to all the matched objects for the 'String' event.

Example:

$("p").bind("click",function(){
  alert("Hello!");
});

The function that is attched to the event is passed one parameter: The event object. You can use it to perform further event actions.

If you wish to cancel a default action and stop the event from bubbling, return false from your function, for example:

$("form").bind("submit",function(){
  return false;
});

To stop the default action OR to stop the event from bubbling, use these methods:

$("form").submit(function(e){
  e.preventDefault(); // Stop form submission
});

$("form").submit(function(e){
  e.stopPropagation(); // Stop event bubbling
});

unbind(String,Function)

Unattaches the specified function from all the matched objects for the 'String' event.

Example:

var b = function(){ alert("Hello!"); };
$("h3").bind("click",b);
$("h3").unbind("click",b);