jQuery doubt append appendTo inject HTML

Asked

Viewed 163 times

5

Hello,

I’m having a doubt.

I have a variable containing an html structure and I need to inject a basic div (< div > < / div >) around all the contents of this variable, as a parent, using only jQuery.

I believe I should use the append and appendTo, but I’m lost.

Any tips? Thank you

1 answer

8


In that case you can use the .wrap() thus:

$(".o-teu-conteudo-existente").wrap("<div class='nova-div'></div>");

That way jQuery changes the content into this new div.

  • 3

    I came here to answer with .append, but your solution is much better! + 1

  • 1

    That’s exactly what it was, thank you !!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.