Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to write the code to process links automatically, not just use the CSS st

ID: 3889583 • Letter: I

Question

I need to write the code to process links automatically, not just use the CSS style to add color to the links. This is the code; I really have no idea hot to do this, I have chapter to and fro. Somewhere along the lines we have switched to Javascript and for the last 4 weeks we have been working with HTML5 and CSS3. I would appreciate some help on this to get it turned by 11.59pm Sunday Night 24th. When I upload this my schools server, the only that shows up on the webpage is the same script as here. Matter of fact here is the web server link. ( http://wmelliott.x10host.com/Week4/Fig14.js ). Yep, this is beyond me, haha.

// Fig12.14: collections.js

// Script to demonstrate using the links collection.

function processLink()

{

var linkList = document.links; // get the document's links

var contents = "<ul>";

// concatenate each link to contents

for ( var i = 0; i , linksList.length; ++i )

{

var currentLink = linksList[ i ];

contents += "<li><a href="" + currentLink.href + "">" +

currentLink.innerHTML + "</li>";

} //end for

contents += "</ul>";

document.getElementById( "links").innerHTML = contents;

} // end function processLinks

window.addEventListener( "load" , processLinks, false );

Explanation / Answer

<html>
<body>
<a href="#something">Something</a>
<a href="http://www.google.com">Google</a>

<div id="links">
</div>

<script>
var arr = [], linkList = document.links;
var contents = "<ul>";
for(var i=0; i<linkList.length; i++)
{
var currentLink = linkList[i];
contents += "<li><a href="" + currentLink.href + "">" +currentLink.innerHTML + "</li>";

}
contents += "</ul>";
document.getElementById( "links").innerHTML = contents;

</script>


</body>

</html>