DOM

Element.hasAttribute() メソッド

 編集:2022.09.22 by T.A.

[Edge]。→

element が指定の属性を持つか否かを真偽値で返します。

構文
element.hasAttribute(attName)
element Element
attName 属性の名前を表す文字列。
戻り値

真偽値。

HTML:

<SPAN id=IdTest class="Test" style="" contenteditable>SPAN要素</SPAN>

JavaScript:

D=IdTest.hasAttribute('class'); //=[boolean]:true
D=IdTest.hasAttribute('style'); //=[boolean]:true
D=IdTest.hasAttribute('contenteditable'); //=[boolean]:true
D=IdTest.hasAttribute('type'); //=[boolean]:false

テスト