0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

jQuery unwrap() 親要素を削除する

Posted at

unwrap() 親要素を削除

例で使うhtml
<div class="hoge1">
  <span class="hoge2">子要素です</span>
</div>

<button class="button">要素を削除します</button>
親要素を削除
$(".button").on("click", function(){
  $(".hoge2").unwrap();
});
削除後のhtml
<span class="hoge2">子要素です</span>

<button class="button">要素を削除します</button>

解説
unwrap() は、指定した要素の親要素を削除し、指定した要素は残します。
例の場合は、親要素である hoge1クラス のみを削除して、指定された hoge2クラス は残します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?