DOM

Element.removeAttribute() メソッド

 編集:2022.09.23 by T.A.

[Edge]。→

element の指定された属性を削除します。

構文
element.removeAttribute(attrName)
element Element
attrName DOMString。削除したい属性の名前。

指定された属性が存在しない場合、エラーは発生させずに戻ります。

戻り値

undefined。

// Given: <div id="div1" align="left" width="200px">
document.getElementById("div1").removeAttribute("align");
// Now: <div id="div1" width="200px">

HTML:

<SPAN id=IdTest type="Test" style="color:red">SPAN要素</SPAN>

JavaScript:

IdTest.removeAttribute('style');
D=IdTest.outerHTML; //=[string]:<span id="IdTest" type="Test">SPAN要素</span>
IdTest.removeAttribute('type');
D=IdTest.outerHTML; //=[string]:<span id="IdTest">SPAN要素</span>
IdTest.removeAttribute('test'); //存在しない属性を削除: エラーは出なかった。

テスト