When loading ajax-generated markup, it will not preserve pre-existing functions. In the above example, you initialize things when the DOM is ready for action. To make sure all plugins, etc. Launched after executing the ajax request, you need to reinitialize them.
Given your code example above, I would recommend a little restructuring. For example, you can create a function called init that you could call to initialize certain plugins:
function init () { $("#plugin-element").pluginName(); } jQuery(document).ready(function () {
Then, after that, with a successful callback of your ajax request, you can call it again, which will reinitialize the plugins:
// inside jQuery(document).ready(...) $.ajax({ type: 'GET', url: 'page-to-request.html', success: function (data, textStatus, jqXHR) { // Do something with your requested markup (data) $('#ajax-target').html(data); // Reinitialise plugins: init(); }, error: function (jqXHR, textStatus, errorThrown) { // Callback for when the request fails } });
source share