繁体   English   中英

Javascript / jquery:删除类的父级并保留它的子级

[英]Javascript/jquery: Remove parent of class and keep it's child

我想用javascript / jquery删除具有特定类名的子节点的父节点。 这是一个我想删除的跨度包装器。 我只知道要使用的孩子的班级(或id)。

我怎样才能做到这一点?

所以这:

<span>
  <input class="removespan" type="text">
</span>

需要这样:

<input class="removespan" type="text">

令人惊讶的是,jQuery有整整这样做的方法: unwrap

$(".removespan").unwrap();

实例:

 setTimeout(function() { $(".removespan").unwrap(); }, 1000); 
 span { border: 1px solid green; padding: 4px; } 
 <div style="margin-bottom: 8px"> The span has a green border. The span is removed after a second: </div> <div> <span> <input class="removespan" type="text"> </span> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM