jQuery doubt append appendTo inject HTML

5

Hello,

I have a question.

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

I think I should use append and appendTo, but I'm lost.

Any tips? Thank you

    
asked by anonymous 18.05.2017 / 14:34

1 answer

8

In this case you can use .wrap() like this:

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

In this way jQuery changes the content into this new div .

    
18.05.2017 / 14:36