I have the following:
var myArray = [];
myArray.push("one", " two");
document.getElementById("write").innerHTML = myArray;
Which outputs: one, two
Thought I'd try it with jQuery:
$("#write").html(myArray);
And I got: one two
It left out the comma.
Why?
I've seen someone suggest that .html()
should be used over .innerHTML()
and that it works the same, but if the jQuery version is leaving out small details, what's the point?
Then I found this post which says "However, the .text()
function will change the (text) value of the specified element, but keep the html structure."
Is this why .text()
seems to work better than .html()
in this particular case? Because .text()
keeps the structure?