getAttribute
In this chapter you will learn:
Get an attribute
The following code sets and gets attributes for an element.
<!DOCTYPE HTML> <!-- j a va 2 s.c om-->
<html>
<body>
<p id="textblock" class="Survey numbers">
This is a test.
</p>
<pre id="results"></pre>
<script>
var elem = document.getElementById("textblock");
document.writeln("lang attribute: " + elem.hasAttribute("lang"));
elem.setAttribute("lang", "en-US");
document.writeln("Attr value is : " + elem.getAttribute("lang"));
elem.setAttribute("lang", "en-UK");
document.writeln("Value is now: " + elem.getAttribute("lang"));
</script>
</body>
</html>
Next chapter...
What you will learn in the next chapter: