js小技巧之访问元素属性
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
</head>
<body>
<div id="roboth"></div>
<script type="text/javascript">
//<![CDATA
//attributes elements NamedNodeMap
var div=document.getElementById("roboth");
alert(div.attributes.getNamedItem("id").nodeValue);
alert(div.attributes.item(0).nodeValue);
alert(div.getAttributeNode("id").nodeValue);
alert(div.getAttribute("id"))
//]]>
</script>
</body>
</html>