It seems that you want to include special characters, such as NO-BREAK SPACE, in your JavaScript string literal. You can do this directly, provided that the character encoding of the file containing the JavaScript code is properly declared, as it should be:
document.getElementById("textField").value = ' ';
Here, the symbol between the apostrophes is the true symbol of NO-BREAK SPACE. In rendering, it is usually indistinguishable from the usual SPACE, but it has different effects. Similarly, you can write, for example.
document.getElementById("textField").value = 'Ξ©';
using the direct link to the Greek letter omega.
If you do not know how to enter such characters (for example, through the Windows CharMap program) or if you cannot manage character encoding problems, you can use JavaScript Unicode escape notifications for characters, for example
document.getElementById("textField").value = '\u00A0'; // no-break space
or
document.getElementById("textField").value = '\u03A9';
For a small character set with Unicode numbers less than 0x100, you can use \x
escape sequences, for example. '\xA0'
instead of '\u00A0'
. (But if you didnβt know this, itβs best to learn how to use the universal \u
escape instead.)
source share