HTML DOM getAttribute()Method

元素对象参考手册Element Object

Examples

Get the value of the link's target attribute:

document.getElementsByTagName("a")[0].getAttribute("target");

Output:

_blank

Try it Yourself »

Definition and Usage

The getAttribute() method gets the value of an attribute by name.

Tip:If you want to return the attribute, use the getAttributeNodemethod.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the getAttribute() method


Syntax

element.getAttribute(attributename)

Parameters

Parameter Type Description
attributename String Required. The value of the attribute you want to get.

Return Value

Type Description
String The specified attribute value

Technical Details

DOM Version Core Level 1 Element Object


元素对象参考手册Element Object

Other Extensions