matchesCssRule.js

概略

対象の要素がスタイルシートで定義されているセレクタ (document.styleSheets[i].cssRules[j].selectorText) にマッチするなら、true を返します。

ダウンロード

サンプル

下記の要素をクリックすると、true または false を alert します。(* コードはブラウザの [ソースを表示] で確認してください。)

「for loop ver.」「Array.forEach ver.」「Array.some ver.」の3タイプが存在します。
「Array.forEach ver.」はマッチしてもループ処理を継続するので、実際に使用する時は他のタイプを選択すると良いと思います。

HTMLDivElement, property = none (for loop ver.)
HTMLDivElement, property = none (Array.forEach ver.)
HTMLDivElement, property = none (Array.some ver.)

HTMLParagraphElement, property = none (for loop ver.)

HTMLParagraphElement, property = none (Array.forEach ver.)

HTMLParagraphElement, property = none (Array.some ver.)

HTMLParagraphElement, property = "height" (for loop ver.)
HTMLParagraphElement, property = "height" (Array.forEach ver.)
HTMLParagraphElement, property = "height" (Array.some ver.)

HTMLParagraphElement, property = "margin" (for loop ver.)

HTMLParagraphElement, property = "margin" (Array.forEach ver.)

HTMLParagraphElement, property = "margin" (Array.some ver.)

参考URL

Selectors API
document.styleSheets
element.style
Array.forEach
その他