![](/img/trans.png)
[英]Jquery html() method not working if we place a div inside a p tag?
[英]jQuery: Use insertAfter method to create p tag inside div tag
我想通过insertAfter方法在其中创建带有p标签的div标签
所以现在我的代码是
$('<p></p>', {
'width': '110',
'height': '110',
}).insertAfter($(this));
现在的输出是这样的
<p style="width:110px;height:110px;"></p>
如何在不重复insertAfter方法的情况下使输出像这样
<div id="wrapP"><p style="width:110px;height:110px;"></p></div>
谢谢
$('<p></p>', {
'width': '110',
'height': '110',
}).insertAfter($(this)).wrap('<div id="wrapP"></div>');
我的方法要求先创建父元素,然后附加子元素:
$('<div id="wrapP" />').append($('<p></p>', {
'width': '110',
'height': '110',
})).insertAfter('body');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.