I'm trying to get the innerText values from all the 'a' tags in my document with this loop.
var x = document.getElementById("toplist-artists");
var y = x.getElementsByTagName("a");
var nodeListLength = y.length;
for (i=0;i<nodeListLength;i++) {
var artists = x.innerText;
}
console.log(artists);
This works and now I want to separate these values with a comma or space. When I add + ',' to x.innertext a comma only shows at the end of the 'list'. Like this:
Tom Odell
Elbow
Aloe Blacc
Michael Prins
,
Can someone please tell me how to get it to show like this
Tom Odell,
Elbow,
Aloe Blacc,
Michael Prins,