user3496563
user3496563

Reputation: 253

Remove div without moving the elements inside of it using jQuery unwrap

I want to remove the div that has class "form-group" but I don't want to remove the code inside of it. jQuery unwrap should do this but I'm not sure how to write the code.

<form class="navbar-form">
<div class="form-group">
<input type="text" id="search" class="form-control" placeholder="Search">
<button class="btn btn-primary modal-search" type="submit">
<span class="icon icon-search"></span>
</button>
</div>       
</form>

Upvotes: 1

Views: 378

Answers (2)

Afzaal Ahmad Zeeshan
Afzaal Ahmad Zeeshan

Reputation: 15860

You can also save the data of the div and then append it to the form once you're done. Here is a fiddle example for that:

http://jsfiddle.net/afzaal_ahmad_zeeshan/pPGj2/

The code was:

var dataContent = $('.form-data').html();
$('.form-data').remove();
$('form').append(dataContent);

Upvotes: 0

Anton
Anton

Reputation: 32581

Use .unwrap()

$('.form-group').children().unwrap();

DEMO

Upvotes: 8

Related Questions