jQuery is()メソッド

❮jQueryトラバースメソッド

<p>の親が<div>要素である場合は、次のテキストを警告します。

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

定義と使用法

is()メソッドは、選択された要素の1つが selectorElementと一致するかどうかを確認します。


構文

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

Parameter Description
selectorElement Required. Specifies a selector expression, element or a jQuery object to match the current set of elements against. Returns true if there is at least one match from the given argument, and false if not.
function(index,element)

Optional. Specifies a function to run for the group of selected elements.

  • index - the index position of the element
  • element - the current element (the "this" selector can also be used)

❮jQueryトラバースメソッド