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 July 2015.

ElementremoveAttribute() メソッドは、指定された名前の属性を要素から削除します。

構文

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①

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
removeAttribute

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.