Javascript DOM HTML document links Collection get href
<html> <head> <title>Using Links Collection</title> <script type = "text/javascript"> function processlinks()/*from w w w . j a va 2s . co m*/ { let linkslist = document.links; // get the document's links let contents = "Links in this page:\n<br />| "; // concatenate each link to contents for ( let i = 0; i < linkslist.length; i++ ) { let currentLink = linkslist[ i ]; contents += "<span class = 'link'>" + currentLink.innerHTML.link( currentLink.href ) + "</span> | "; } // end for document.getElementById( "links" ).innerHTML = contents; } </script> </head> <body onload = "processlinks()"> <h1>Deitel Resource Centers</h1> <p><a href = "http://www.java2s.com/">website</a> contains a rapidly growing <a href = "http://www.java2s.com">list of Resource Centers</a> on a wide range of topics. <a href = "http://www.java2s.com">Java</a>, <a href = "http://www.java2s.com">Javascript</a>, <a href = "http://www.java2s.com">C++</a>, <a href = "http://www.java2s.com">C</a>, <a href = "http://www.java2s.com">HTML</a>, <a href = "http://www.java2s.com">Go</a>. </p> <div id = "links" class = "links"></div> </body> </html>