share
Stack OverflowJquery plugins not working on ajaxed content
[0] [1] user272899
[2010-03-26 23:40:20]
[ jquery ajax plugins ]
[ https://stackoverflow.com/questions/2527489/jquery-plugins-not-working-on-ajaxed-content ]

I have some content that I am loading using jquery ajax. The content has jquery plugins attached (example a modal box).

My problem is that because the ajaxed content isn't part of the original dom it hasn't had the plugins applied to it.

How do I apply the plugins to ajaxed content??? Is there someway I can reinitialize i the plugins???

Question is to vague. Show sample of loaded content and detail which jQuery method you use to load the content. There are e.g. some calls which strip existing script tags - jitter
[+1] [2010-03-26 23:48:38] Nick Craver [ACCEPTED]

You can call the plugin in the ajax success function like this:

$.ajax({
  //Stuff..
  success: function(data) {
    $(".selector", data).myPlugin();
  }
});

This calls the plugin on the matching selector only in the html that was returned, so it won't run on the rest of the page again.


Hell yeah I wish I knew how to do that before. Would have avoided alot of issues - user272899
1