JavaScript - How to add links to the DOM -


I'm new to javascript, so this question might be easy for you:

I 'DOM Trying to add an additional URL link, but my current code is not working. In my mind, my code should work perfectly, but the code should think itself otherwise.

  // Additional URL link which will come under the first one // establish a connection in the DOM var target = Document.getElementsByTagName ("A"); // We need to create new element var newLink = document.createElement ("a"); // Our new "A" tag has been created, but we have to add some things to NewLink.setAttribute ("href", "http://www.ign.com/"); // Now we need to add some text to the new user, click the new "A" element newLink.appendChild (document.createTextNode ("click me!");); // Finally, add a new element and we have golden goals .appendChild (newLink);  

change target.appendChild (newLink); to target [0] .appendChild (newLink);

"target" an array all links A elements in your code, so that you target [0] ]

Need to say,

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -