JavaScript DHTML/Node Operation/getAttribute
Версия от 10:02, 26 мая 2010; (обсуждение)
Display attributes for hyper link
<html>
<head>
<title>Show Attribs</title>
<script type = "text/javascript">
function showattribs(e) {
var e = document.getElementById("website");
var elemList = "";
for (var element in e) {
var attrib = e.getAttribute(element);
elemList = elemList + element + ": " + attrib + "\n";
}
document.write(elemList);
}
</script>
</head>
<body>
<a onclick="showattribs()" href="http://www.google.ru" id="website">link</a>
</body>
</html>
"getAttribute()" Example
<html>
<body>
<script language="JavaScript">
function function1(){
var m = document.getElementById("myDiv").getAttribute("id");
alert(m);
}
</script>
<div id="myDiv">This is a div element</div>
<input type="button" value="Get id attribute value" onclick="function1();">
</body>
</html>