-1

I want to append the text <b>text</b> to an element as a child without changing it into HTML.

append('<b>text</b>') gives bold content text, but I want the text to be <b>text</b>.

Ovilia
  • 6,871
  • 12
  • 45
  • 68

2 Answers2

3

Append a text node:

.append(document.createTextNode('<b>text</b>'));
David Hellsing
  • 102,045
  • 43
  • 170
  • 208
0

You have to mix up native js to accomplish this,

var node = document.createTextNode("<b>test</b>");
$('element')[0].appendChild(node);

DEMO

Balachandran
  • 9,427
  • 1
  • 14
  • 25