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