File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
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?
I agree. Here's the link:
subject: lost space after setting innerHTML
It's not a secret anymore!