JavaScript gets the method for the first anchored text on a page

  • 2020-05-26 07:42:46
  • OfStack

This example shows how JavaScript gets the first anchored text on a page. Share with you for your reference. The details are as follows:

The JS code below gets the innerHTML of the first archor through the document.archors array


<!DOCTYPE html>
<html>
<body>
<a name="html">ofstack.com</a><br>
<a name="css">CSS Tutorial</a><br>
<a name="xml">XML Tutorial</a>
<p>innerHTML of the first anchor:
<script>
document.write(document.anchors[0].innerHTML);
</script>
</p>
</body>
</html>

The above code output:


ofstack.com

I hope this article is helpful for you to design javascript program.


Related articles: