HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML DOM 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


Element Object Reference Element Object


Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE