Table of Contents

<HTMLElement>.getText()

Returns the text content of an Element (including from sub-elements).

Usage:
String = Element..getText()
Member of:
HTMLElement
Parameters:
none
Returns:
The text content of the parent HTMLElement as String.
Notes:
  • This is just a simple wrapper for the built-in .textContent method.
  • The returned String contains all non-Element text nodes, including possible <script> or <style> element contents.
  • This method does not take into account hiding of content e.g. via CSS.

Examples

Simple example:

console.log(document.getElementById('foo').getText());

See also

More information