Search code examples
jqueryajaxjquery-load

How to use .load function inside a .wrap function


I want to wrap content retrieved with load in jQuery, but I am not sure of the correct syntax, or possibly it's not possible to combine the two this way.

This is throwing an Uncaught TypeError:

$('video').wrap(function(){
        $.load('videoholder.php');
});

Solution

  • You need to execute the wrap in a callback (after the AJAX response comes back).

    See: JQuery .load() callback function