Document anchors Collection - Get the HTML content of the first <a> element in the document: - Javascript DOM

Javascript examples for DOM:Document anchors

Description

Document anchors Collection - Get the HTML content of the first <a> element in the document:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<a name="html">HTML Tutorial</a><br>
<a name="css">CSS Tutorial</a><br>
<a name="xml">XML Tutorial</a><br>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from  w w  w .  ja va  2  s.c  o m*/
    var x = document.anchors[0].innerHTML;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials