Pages
    • GETTING STARTED
        • API REFERENCE
                                                                                                                                              • COMMAND LINE
                                                                                                                                                  On this page

                                                                                                                                                          .getTextNodes()

                                                                                                                                                          This method is used to get all text nodes within an element.

                                                                                                                                                          Syntax

                                                                                                                                                          let textNodes = $(el).getTextNodes();

                                                                                                                                                          Return

                                                                                                                                                          • textNodes: Array - The text nodes found; each an instance of Text.

                                                                                                                                                          Usage

                                                                                                                                                          Return all text nodes in the document.

                                                                                                                                                          let textNodes = $(document.body).getTextNodes();
                                                                                                                                                          textNodes.forEach(node => {
                                                                                                                                                              // Show text content
                                                                                                                                                              console.log(node.wholeText);
                                                                                                                                                              // Replace text content
                                                                                                                                                              node.textContent = 'New text content.';
                                                                                                                                                          });

                                                                                                                                                          Static Usage

                                                                                                                                                          The .getTextNodes() instance method is internally based on the standalone dom/getTextNodes() function which may be used statically.

                                                                                                                                                          Import

                                                                                                                                                          const { getTextNodes } = $.dom;
                                                                                                                                                          import { getTextNodes } from '@webqit/playui-js/src/dom/index.js';

                                                                                                                                                          Syntax

                                                                                                                                                          See the general way to use Play UI's standalone functions