このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。
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() メソッドは、指定された名前の属性を要素から削除します。
In this article
構文
js
removeAttribute(attrName)引数
attrName文字列で、要素から削除する属性名を指定します。指定した属性が存在しなかった場合、
removeAttribute()はエラーを発生させずに戻ります。
返値
なし (undefined)。
使用上のメモ
属性の値を直接、またはsetAttribute() を使用してnull に設定するのではなく、removeAttribute() を使用してください。多くの属性はnull に設定しても、期待通りの動作をしません。
例
js
// Given: <div align="left" width="200px">document.getElementById("div1").removeAttribute("align");// Now: <div width="200px">仕様書
| Specification |
|---|
| DOM> # ref-for-dom-element-removeattribute①> |