document.anchors of a page by JavaScript

document.anchors can be give us all the anchors present in the document ( page ). Note that we must have name attribute on the anchors. Here is an example anchor with name
<a href=www.plus2net.com name='home'>plus2net.com</a>
document.anchors returns an array and we can find the number of elements present inside it by length property.
Here is a sample code to understand document.anchors
<html>
<head>
<title></title>
</head>
<body>
<a href='https:www.plus2net.com' name='first'>Plus2net Home</a><br>
<a href='https://www.plus2net.com/php_tutorial/site_map.php' name='second'>PHP tutorial</a>
<br><br>

<script type="text/javascript">
document.write(document.anchors.length); // output 2
document.write("<br>");
document.write(document.anchors[1].innerHTML);  // PHP tutorial
document.write("<br>");
document.write(document.anchors[1].name); // second
document.write("<br>");
document.write(document.anchors[1].href); //https://www.plus2net.com/php_tutorial/site_map.php
</script>

</body>
</html>

document Object URL of the page
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer