jQuery is() メソッド

❮ jQuery Traversing メソッド

<p> の親が <div> 要素の場合、テキストをアラートする:

if ($("p").parent().is("div")) {
    alert("Parent of p is div");
}
Try it Yourself »

定義と用法

is() メソッドは、選択した要素の 1 つが selectorElement に 一致するかどうかをチェックします。


構文

$(selector).is(selectorElement,function(index,element))

パラメータ 説明
selectorElement 必須。現在の要素の集合に対して、マッチするためのセレクタ式、要素、または jQuery オブジェクトを指定する。指定の引数に少なくとも 1 つがマッチした場合は true が、 それ以外は false が返される
function(index,element)

任意。選択した要素のグループに実行する関数。

  • index - 要素のインデクス位置
  • element - 現在の要素 ("this" セレクタも使用できる)

❮ jQuery Traversing メソッド