Search w3schools.com:

SHARE THIS PAGE

DOM Element getAttribute() Method

Element Object Reference Element Object

Example

Get the target attribute value of a link:

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

The result will be:

_blank

Try it yourself »

Definition and Usage

The getAttribute() method returns the value of the attribute with the specified name.

Tip: Use the getAttributeNode if you want to return the attribute as an Attr object.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The getAttribute() method is supported in all major browsers.


Syntax

element.getAttribute(attributename)

Parameters

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

Return Value

Type Description
String The specified attribute's value

Technical Details

DOM Version Core Level 1


Element Object Reference Element Object


Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]