DOM element getAttribute () method
Examples
Get target property value links:
document.getElementsByTagName("a")[0].getAttribute("target");
Output:
_blank
try it"
Definition and Usage
getAttribute () method to get the value of an attribute by name.
Tip: If you want to return property use getAttributeNode methods.
Browser Support
All major browsers support getAttribute () method
grammar
element.getAttribute( attributename )
parameter
参数 | 类型 | 描述 |
---|---|---|
attributename | String | 必须。你想获取的属性值。 |
return value
类型 | 描述 |
---|---|
String | 指定属性值 |
technical details
DOM version | Core Level 1 Element Object |
---|