== .appendText==

.appendText()

Appends a new Text node to the parent element (as the last child element).
Usage:
[[mdn>Web/API/HTMLElement|HTMLElement]] = Element.''appendText''(text)
Member of:
[[mdn>Web/API/HTMLElement|HTMLElement]]
Parameter:
text – the text to add (required).
Returns:
The [[mdn>Web/API/HTMLElement|HTMLElement]] it was called on, thus allowing for command chaining.
Notes:
* This function encodes HTML special characters (''<'', ''>'', ''%%&%%'', ''%%"%%'' and ''%%'%%'') before creating the text node, thus HTML code passed as parameter will be displayed as //text// rather than parsed into a DOM structure. If you want to parse HTML code, please use the [[toolbox:element:sethtml:index|.setHtml()]] function instead.
===== Examples ===== Simple example: let foo = document.getElementById('foo'); foo.appendText('Hello world!'); ===== See also ===== * [[toolbox:element:prependtext:index|.prependText()]] * [[toolbox:element:sethtml:index|.setHtml()]] ===== More information ===== * [[mdn>Web/API/Element/append|Node: append() method]] on MDN. * [[mdn>Web/API/Document/createTextNode|Document: createTextNode() method]] on MDN.