[英]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.