Skip to content

Instantly share code, notes, and snippets.

@avireni
Created April 13, 2012 23:17
Show Gist options
  • Save avireni/2380741 to your computer and use it in GitHub Desktop.
Save avireni/2380741 to your computer and use it in GitHub Desktop.
set an event handler for any element that matches a selector
$('button.someClass').live('click', someFunction);
//Note that in jQuery 1.4.2, the delegate and undelegate options have been
//introduced to replace live as they offer better support for context
//For example, in terms of a table where before you would use..
// .live()
$("table").each(function(){
$("td", this).live("hover", function(){
$(this).toggleClass("hover");
});
});
//Now use..
$("table").delegate("td", "hover", function(){
$(this).toggleClass("hover");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment