Reputation: 6824
This is not a question to make any code work, but more an issue of OCD :-)
If I have this code:
<div id="div1">The text above has been created dynamically.</div>
and in my JavaScript I write this:
var div1 = document.getElementById("div1").innerHTML;
console.log(div1);
Then I get this output in the browser:
"The text above has been created dynamically."
But when I do this in my HTML:
<div id="div1">
The text above has been created dynamically.
</div>
Then I get this in my console:
"
The text above has been created dynamically.
"
You can see there is a huge gap. Now in my actual webpage it makes no difference, but I like tidy code :-) So as far as I can tell I can't have tidy html and a tidy javascript console output.
Am I correct in this or can I change this? I know it seems a petty thing, but I would like to remove the unnecessary spaces in my console if I can.
Thanks.
Upvotes: 0
Views: 97
Reputation: 13497
Seems like you could accomplish what you're looking for (prettier logging) with String.prototype.trim()
:
console.log(div1.innerHTML.trim());
Upvotes: 1