Search code examples
javascriptdomhtml-entitiesnodevalue

Setting nodeValue of text node in Javascript when string contains html entities


When I set a value of a text node with

node.nodeValue="string with &#xxxx; sort of characters"

ampersand gets escaped. Is there an easy way to do this?


Solution

  • You need to use Javascript escapes for the Unicode characters:

    node.nodeValue="string with \uxxxx sort of characters"