css - jquery - how to remove wrapper div element?

非 Y 不嫁゛ 提交于 2019-12-25 16:41:18

问题


I have an HTML like this.

<div class="wrapper">
    <input class="myClass" ....>
</div>

I want to remove the wrapper div with class 'wrapper' so that the output will be.

<input class="myClass" ....>

Would be great if it is done with jquery.


回答1:


Use .unwrap(). Try this:

$('.wrapper').children().unwrap();

DEMO




回答2:


use .replaceWith() in jquery

$('.wrapper').replaceWith(function() {
 return $('input ', this);
});

Fiddle



来源:https://stackoverflow.com/questions/22762279/css-jquery-how-to-remove-wrapper-div-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!