Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

lost space after setting innerHTML  RSS feed

 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!