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 name='home'></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
<a href='' name='first'>Plus2net Home</a><br>
<a href='' name='second'>PHP tutorial</a>

<script type="text/javascript">
document.write(document.anchors.length); // output 2
document.write(document.anchors[1].innerHTML);  // PHP tutorial
document.write(document.anchors[1].name); // second
document.write(document.anchors[1].href); //


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


* indicates required
Subscribe to plus2net

    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 All rights reserved worldwide Privacy Policy Disclaimer