[英]jQuery wrap not working with append?
p
element <p id="test">Test</p>
and wrap it inside a span
by using wrap
and save the new element under $test
. p
元素<p id="test">Test</p>
并通过使用wrap
并将其包装在span
,并将新元素保存在$test
。 $test
to p#output
. $test
追加到p#output
。 Result : p
element is getting appended, but it is not wrapped inside a span anymore. 结果 :
p
元素将被追加,但不再包装在span中。
$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>
jQuery documentation says .wrap()
returns the original set of elements for chaining purposes. jQuery文档说
.wrap()
返回原始元素集以进行链接。
use something like this instead $("p#output").append($('p#test').parent());
使用类似这样的东西
$("p#output").append($('p#test').parent());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.