Skip to content Skip to sidebar Skip to footer

Simple Javascript Append Array Link Ids To Html Doc?

I have an array of hypothetical JavaScript link ids myArray = ['id1', 'id2', 'id3']; How do I create each link element and append it to the html document?

Solution 1:

var myArray = ["id1", "id2", "id3"];
var container = document.getElementById('container');
myArray.forEach(function(id){
  container.innerHTML =  container.innerHTML + "<a href=\""+id+"\">"+id+"</a>"
}); 

http://jsfiddle.net/suwJr/


Post a Comment for "Simple Javascript Append Array Link Ids To Html Doc?"