title | short-title | slug | l10n | ||
---|---|---|---|---|---|
Element: removeAttribute() メソッド |
removeAttribute() |
Web/API/Element/removeAttribute |
|
{{ APIRef("DOM") }}
{{domxref("Element")}} の removeAttribute()
メソッドは、指定された名前の属性を要素から削除します。
removeAttribute(attrName)
attrName
- : 文字列で、要素から削除する属性名を指定します。指定した属性が存在しなかった場合、
removeAttribute()
はエラーを発生させずに戻ります。
- : 文字列で、要素から削除する属性名を指定します。指定した属性が存在しなかった場合、
なし ({{jsxref("undefined")}})。
属性の値を直接、または {{domxref("Element.setAttribute", "setAttribute()")}} を使用して null
に設定するのではなく、 removeAttribute()
を使用してください。多くの属性は null
に設定しても、期待通りの動作をしません。
// Given: <div id="div1" align="left" width="200px">
document.getElementById("div1").removeAttribute("align");
// Now: <div id="div1" width="200px">
{{Specifications}}
{{Compat}}