0

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');
});
Damon
  • 10,493
  • 16
  • 86
  • 144

4 Answers4

1

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

See: JQuery .load() callback function

Community
  • 1
  • 1
Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
0

No, that's not the correct syntax.

$('video').load('videoholder.php')
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
0

What Diodeus said. Try this:

$.load('videoholder.php', function(response, status, xhr) {
    $('video').wrap(response);
})
Blazemonger
  • 90,923
  • 26
  • 142
  • 180
  • that's throwing the same error. think I have to load the php into something initially? – Damon Aug 26 '11 at 19:07
  • 1
    First idea: make sure jQuery is loading properly. Second idea: Exactly what code is your videoholder.php script returning? It should be a valid HTML snippet that works with wrap(). http://api.jquery.com/wrap/ – Blazemonger Aug 26 '11 at 19:09
-1

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

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

;

aziz punjani
  • 25,586
  • 9
  • 47
  • 56