Table of Contents

<HTMLElement>.prependText()

Prepends a new Text node to the parent element (as the first child element).

Usage:
HTMLElement = Element.prependText(text)
Member of:
HTMLElement
Parameter:
text – the text to add (required).
Returns:
The 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 .setHtml() function instead.

Examples

Simple example:

let it = document.getElementById('foo');
it.prependText('Hello world!');

See also

More information