Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery. get text() to preserve blanks/spaces

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.

like image 992
user984003 Avatar asked May 18 '13 16:05

user984003


1 Answers

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

like image 83
techfoobar Avatar answered Sep 22 '22 06:09

techfoobar