This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Getting MEAN with Mongo, Express, Angular, and Node and have Simon Holmes on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes lost space after setting innerHTML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "lost space after setting innerHTML" Watch "lost space after setting innerHTML" New topic

lost space after setting innerHTML

Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
When you have some code like this:
<span>I</span><span> love</span><span> her.</span>
The web page looks like this:
I love her.
But if the code looks like this:
<span>I</span><span id="lovespan"></span><span> her.</span>
And then you have a code line in JavaScript like this:
document.getElementById("lovespan").innerHTML=" love";
The web page looks like this:
Ilove her.
When changing the innerHTML, the space at the beginning of the word " love" is dropped. I could do this:
document.getElementById("lovespan").innerHTML=" love";
But I want the word "love" to wrap to the next line if need be. Any ideas on how to display "I love her." by setting the innerHTML?
Don't get me started about those stupid light bulbs.
subject: lost space after setting innerHTML