Reputation: 301
I want to create a div tag with p tag inside it by insertAfter method
So now My code is
$('<p></p>', {
'width': '110',
'height': '110',
}).insertAfter($(this));
The output now like this
<p style="width:110px;height:110px;"></p>
How to make the output to be like this without repeating insertAfter method
<div id="wrapP"><p style="width:110px;height:110px;"></p></div>
Thank You
Upvotes: 0
Views: 133
Reputation: 44740
$('<p></p>', {
'width': '110',
'height': '110',
}).insertAfter($(this)).wrap('<div id="wrapP"></div>');
Demo -->
http://jsfiddle.net/PCQrP/3/
Upvotes: 2
Reputation: 29251
My approach requires creating the parent element first, and then appending the child:
$('<div id="wrapP" />').append($('<p></p>', {
'width': '110',
'height': '110',
})).insertAfter('body');
Upvotes: 1