RyGuy
RyGuy

Reputation: 508

jQuery events within dynamic content via ajax

Is there a way I can load content dynamically using ajax and retain any jquery functionality that the loaded content may have?

For example, I'd like to load in a Twitter like feed of DB records. Each record can be voted thumbs up or thumbs down. The voting uses some AJAX and I can't retain event functionality when loaded into a parent page.

ok forgive such a noob question but I'm lost with the example on the jquery page. When it says:

$('a').click(fn); 
$('#mydiv').load('my.html',function(){ 
$('a').click(fn); });

what is fn supposed to represent?

Upvotes: 3

Views: 1044

Answers (1)

John Strickler
John Strickler

Reputation: 25421

Use event delegation, .live() or .delegate() will do the trick. It has a lot more advantages than just retaining functionality too.

Upvotes: 9

Related Questions