Latest web development tutorials

DOM Element setAttribute () method

Elements Object Reference Element object

Examples

Set the input element's type attribute:

document.getElementsByTagName("INPUT")[0].setAttribute("type","button");

Setting properties ago:

Setting property:


try it"

Definition and Usage

setAttribute () method to create or change a new property.

If the specified attribute already exists, only set the value.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support setAttribute () method

Internet Explorer 8 and earlier versions of IE does not support this method.


grammar

element .setAttribute( attributename , attributevalue )

parameter

参数 类型 描述
attributename String 必须。你要添加的属性名称。
attributevalue String 必须。你要添加的属性值。

return value

No return value.

technical details

DOM version Core Level 1 Element Object


Elements Object Reference Element object