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

                                                                                                                                                              .textAsync()

                                                                                                                                                              This method is used to asynchronously set or get an element's text content. It is the programmatic alternative to Element.innerText. Additionally, when this function receives undefined for a set operation, it is converted to an empty string.

                                                                                                                                                              The suffix Async differentiates this method from its Sync counterpart - .textSync(). Unlike the Sync counterpart, this method is promised-based. See Async UI.

                                                                                                                                                              a. Set Text Content

                                                                                                                                                              Syntax

                                                                                                                                                              // Set text content of an element
                                                                                                                                                              await $(el).textAsync(content);

                                                                                                                                                              Parameters

                                                                                                                                                              • content: String - The text content to set.

                                                                                                                                                              Return

                                                                                                                                                              • this - The Play UI instance.

                                                                                                                                                              Usage

                                                                                                                                                              Replace an element's content with some text.

                                                                                                                                                              let text = 'Playful people!';
                                                                                                                                                              $(el).textAsync(text);

                                                                                                                                                              b. Get Text Content

                                                                                                                                                              Syntax

                                                                                                                                                              // Get Text content of an element
                                                                                                                                                              let content = await $(el).textAsync();

                                                                                                                                                              Return

                                                                                                                                                              • content: String - The element's text content.

                                                                                                                                                              Usage

                                                                                                                                                              Get an element's text content.

                                                                                                                                                              let content = await $(el).textAsync();
                                                                                                                                                              // Playful people!

                                                                                                                                                              Static Usage

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

                                                                                                                                                              Import

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

                                                                                                                                                              Syntax

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