Suppose that I have an array. How can I wrap each element in the array in a span tag? Also, if I want to .appendchild each span element to a div element, how can I do it?
function add_span(arr){
var new_arr= document.createElement("span");// arr is passed in correctly
var text=document.createTextNode(arr); // text cannot be output
new_arr.appendChild(text);
return new_arr;
}
and in the main:
for (i = 0; i < unique_array.length; i++)
{
span_array[i]=add_span(unique_array[i]);
}
var cloud_text=document.createTextNode(span_array);
cloud.appendChild(cloud_text);
the output now looks like this:
[object HTMLSpanElement],[object HTMLSpanElement],[object HTMLSpanElement],[object HTMLSpanElement],[object HTMLSpanElement],[object HTMLSpanElement],[object HTMLSpanElement],[object HTMLSpanElement],[object HTMLSpanElement],[object HTMLSpanElement],[object HTMLSpanElement]