Non-breaking Space Using MooTools setText()

Posted in JavaScript
2009-10-08 01:34:10 +0000 UTC

I was working on a bit of script today, and happened upon an interesting happenstance. I was trying to change the text of an element dynamically, and this text needed to include a non-breaking space. My original code seemed to render the entity as text, so this:

elem.setText( ' ' );

literally printed the text " " instead of the proper entity.

My solution ended up being to change the entity entirely:

elem.setText( '\\u00a0' );