jQuery hasClass()メソッド

❮jQueryHTML/ CSSメソッド

<p>要素に「intro」という名前のクラスがあるかどうかを確認します。

$("button").click(function(){
  alert($("p").hasClass("intro"));
});

定義と使用法

hasClass()メソッドは、選択された要素のいずれかに指定されたクラス名があるかどうかを確認します。

選択した要素のいずれかに指定されたクラス名がある場合、このメソッドは「true」を返します。


構文

$(selector).hasClass(classname)

Parameter Description
classname Required. Specifies the class name to search for in the selected elements

❮jQueryHTML/ CSSメソッド