Another snippet
I'm using some artifact variables, so excuse the nonsensicality (we'll pretend that's a word), but I thought I'd post a small problem I was having with posting a list using line breaks in JavaScript. \n and <br> would not work, so the solution I came up with was this:
var pre = document.createElement('br'); for (i = 0; i < friends.data.length; i++) { greetingText = document.createTextNode(friends.data[i].name + "\n"); pre = document.createElement('br'); userName.appendChild(pre); userName.appendChild(greetingText); }
Without re-defining pre each time, it only ends up adding one <br> to the list, just before the last. No idea why it overrides, but I assume the guys who wrote it that way had their reasons. I hope this saves somebody some time!












