nevrx
nevrx

Reputation: 37

how to add an object in a div

let's say I have the following code:

var cont = <div id="foo">

imgSection.find('video').each(function(_ind)
{
     cont.append('<div class="fullScreenBg"> '+ $(this) +' </div>');
});

which results in:

<div id="foo"> 
<div class="fullScreenBg"> [object Object] </div>
</div>

But I actually want do display the html of the Object/Video. When I use instead:

$(this).html()

I get pretty close, but it shows, as expected, only the innerHtml of the videoTag. So how do I do this right?

Upvotes: 1

Views: 178

Answers (2)

Felix Kling
Felix Kling

Reputation: 817228

Alternatively, create DOM elements instead of using HTML:

var $parent = $('<div class="fullScreenBg" />');
$parent.append(this).appendTo(cont);

Upvotes: 0

Rory McCrossan
Rory McCrossan

Reputation: 337733

You need to wrap the video element in the div and append the object. The issue at the moment is that you are appending the object as a string which is causing the object to string conversion, resulting in [object Object].

imgSection.find('video').each(function(_ind) {
     cont.append($(this).wrap('<div class="fullScreenBg"></div>').parent());
});

Upvotes: 1

Related Questions