css - jquery - how to remove wrapper div element?

2019-09-07 21:19发布

问题:

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



标签: jquery css class