Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

DOM Element getAttribute() method

HTML DOM getAttribute() method

Element Object Reference Element object

Example

Get the value of the target attribute of the link:

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

Output result:

_blank

Try it »


Definition and Usage

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

**Tip:** If you want to return the attribute, please use the getAttributeNode method.


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the getAttribute() method


Syntax

element

.getAttribute(

attributename

)

Parameters

Parameters Type Description
attributename String Required. The attribute value you want to get.

Return Value

Type Description
String The specified attribute value

Technical Details

DOM version Core Level 1 Element Object

Element Object Reference Element object