简体   繁体   中英

jQuery: Append doesn't work with leading spaces

If I use jQuery's .append() with a string that has leading spaces, it skips the spaces.

Example: $("#div").append(" test"); appends test without the four spaces that are in front of it.

How would I allow the appending of leading spaces?

Are you expecting to see the white space on the page? if so, you need to use   s or non-breaking spaces.

demo: http://jsfiddle.net/W6RMA/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM