printing elements with javascript -


I am currently learning JavaScript and the code given below does not produce results, I thought it would be : var link = document.getElementsByTagName ("a"); (I = 0; i & lt; links.length; i ++) for {document.write (link [i]); }

When I run this code, it writes 1 element with an array.

What did I do?

postprop = "text">

link is a live node list (see). Any change in the link on the page will be spread in the list immediately .

With the first document.write you are overwriting the existing document (if used after the document is loaded), hence the link < / Code> the list will be empty.

use console.log () instead of document.write and javascript in your browser See Replace Console.

  var link = document.getElementsByTagName ("a"); for (i = 0; i  links.length; i ++) {console.log (Link [i]);}    

Comments