开发者

How to use .load function inside a .wrap function

开发者 https://www.devze.com 2023-03-30 21:25 出处:网络
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.

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('videohold开发者_StackOverflow社区er.php');
});


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

See: JQuery .load() callback function


No, that's not the correct syntax.

$('video').load('videoholder.php')


What Diodeus said. Try this:

$.load('videoholder.php', function(response, status, xhr) {
    $('video').wrap(response);
})


Use the callback in the load function and wrap the returned data.
Some rough code below.

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

;

0

精彩评论

暂无评论...
验证码 换一张
取 消