Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  175] [ 5]  / answers: 1 / hits: 66690  / 11 Years ago, wed, november 6, 2013, 12:00:00

I'm generating content dynamically and in some instances, I need to set a &nbsp; as the only content of a <span> element.



However, the following adds &nbsp; as text vs adding a empty space:



var foo = document.createElement(span)
foo = document.createTextNode(&nbsp;);


which makes sense, so I'm wondering, how would I add &nbsp; correctly without (!) using innerHTML



Thanks for help!


More From » whitespace

 Answers
81

You can use a unicode literal for a non breaking space:



var foo = document.createTextNode(u00A0);

[#74476] Tuesday, November 5, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leighamarleem

Total Points: 75
Total Questions: 121
Total Answers: 111

Location: Norway
Member since Mon, May 23, 2022
2 Years ago
;