Element: removeAttribute() メソッド
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
Element の removeAttribute() メソッドは、指定された名前の属性を要素から削除します。
構文
js
removeAttribute(attrName)
引数
attrName-
文字列で、要素から削除する属性名を指定します。指定した属性が存在しなかった場合、
removeAttribute()はエラーを発生させずに戻ります。
返値
なし (undefined)。
使用上のメモ
属性の値を直接、または setAttribute() を使用して null に設定するのではなく、 removeAttribute() を使用してください。多くの属性は null に設定しても、期待通りの動作をしません。
例
js
// Given: <div id="div1" align="left" width="200px">
document.getElementById("div1").removeAttribute("align");
// Now: <div id="div1" width="200px">
仕様書
| Specification |
|---|
| DOM> # ref-for-dom-element-removeattribute①> |
ブラウザーの互換性
Loading…