9
12

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 5 years have passed since last update.

jQuery:あるDOM要素の祖先に特定のDOM要素があることを調べる。

Last updated at Posted at 2014-12-05

jQueryオブジェクトのclosest("セレクタ")メソッドで、特定の親要素を取得することが可能。
よって、以下のように使用する。

使用方法
if($("あるDOM要素のセレクタ").closest("特定の親DOM要素のセレクタ").length > 0){
 alert('親DOM要素に特定のものが存在します!');
}
if($("#childElement").closest(".SpecialParent").length > 0){
 alert('SpecialParent発見');
}
9
12
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?