How do I get jQuery text() to preserve blanks? I want
$("#ele").text("a a");
to actually show up with the spaces in between.
I have created a JSFiddle to illustrate the problem.
https://jsfiddle.net/ZX4x9/
.html()
works, but then I'd have to convert the other entities first (<
, >
, "
, etc.). And, it seems that text()
should be able to do this.
The problem is not with .text()
. If you want consecutive and other stray spaces to show up, you can use white-space: pre
for your <li>
s:
ul li {
white-space: pre;
}
See this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With