Reputation: 20382
p
element <p id="test">Test</p>
and wrap it inside a span
by using wrap
and save the new element under $test
.$test
to p#output
.Result: p
element is getting appended, but it is not wrapped inside a span anymore.
$test = $("p#test").wrap("<span style='color:red'></span>");
$("p#output").append($test);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="test">Test</p>
<p id="output">OUTPUT:</p>
Upvotes: 0
Views: 1196
Reputation: 6917
jQuery documentation says .wrap()
returns the original set of elements for chaining purposes.
use something like this instead $("p#output").append($('p#test').parent());
Upvotes: 3