2014-01-13 96 views

回答

1

可以使用wrapAll包裹所有內包裹,並通過使用contents除去內側包皮像下面使用unwrap

使用如下數據:demo

$('.inner').wrapAll('<div class="new" />').contents().unwrap(); 

還是用這樣的:demo

$('.inner p').unwrap().wrapAll('<div class="new" />'); 
+2

@Ahmad你錯誤地編輯我的答案和改變內部集裝箱和人們幾乎要冷靜下來。編輯答案時請注意! –

2

您可以使用.unwrap().wrapAll()方法:

$('.container p').unwrap().wrapAll('<div class="new"></div>'); 

jsFiddle