Re-binding jQuery Events on AJAX Callbacks

Posted by Jetlogs @ 1:48 pm
Category: jQuery,Web Development

Or the title can be put shortly as: Why doesn’t my jQuery events work after an AJAX callback?

Lets create a very simple example jQuery script which simply changes a list’s class on hover:

We’ll assign red as the hover color:

<style type="text/css">
.hover
{
	color: #f00;
}
</style>

Then add the jQuery hover() event to toggle/change the list’s class when the mouse hovers over the list. This is how the javascript code will look like inside the document.ready() function:

$("li").hover(
function()
{
	$(this).toggleClass("hover");
},
function()
{
	$(this).toggleClass("hover");
});

Read more »


  • Archives

  • Donations

  • Social Bookmarks

  • Jetlogs.org
    Some Rights Reserved 2007
    Creative Commons License