Returns an array of attributes on the given element.
Syntax
attributes = elementNode.attributes
Parameters
attributes is a namedNodeMap of attributes on the current element.
Example
// get the first <p> element in the document
para = document.getElementsByTag("p")[0];
atts = para.attributes;
|
Notes
The array returned by this property is a namedNodeMap, a list of objects rather than strings. The name and value of the attribute objects are accessible as separate properties, as in the following complete example, which retrieves the name/value pair of the first attribute of the "p1" paragraph in the document:
<html>
<head>
<script>
function showA() {
p = document.getElementById("p1");
t = document.getElementById("t");
t.setAttribute("value",
p.attributes[0].name + "->" + p.attributes[0].value);
}
</script>
</head>
<p id="p1" style="color: blue;">Sample Paragraph</p>
<form>
<input type="button" value="show" onclick="showA()" />
<input id="t" type="text" value="" />
</form>
</html>
|
Specification
core