【问题标题】:Remove div without moving the elements inside of it using jQuery unwrap使用 jQuery unwrap 删除 div 而不移动其中的元素
【发布时间】:2014-04-25 09:57:30
【问题描述】:

我想删除具有“form-group”类的 div,但我不想删除其中的代码。 jQuery unwrap 应该这样做,但我不知道如何编写代码。

<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>

【问题讨论】:

  • 你想把它从 DOM 中删除,还是只删除到 $.hide() 它?

标签: jquery


【解决方案1】:

使用.unwrap()

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

DEMO

【讨论】:

    【解决方案2】:

    您还可以保存 div 的数据,然后在完成后将其附加到表单中。这是一个小提琴示例:

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

    代码是:

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

    【讨论】:

      猜你喜欢
      • 2011-09-23
      • 1970-01-01
      • 2017-05-10
      • 1970-01-01
      • 2021-12-05
      • 1970-01-01
      • 2014-01-05
      • 1970-01-01
      • 2013-09-15
      相关资源
      最近更新 更多