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

                                                                                                                                                              .textSync()

                                                                                                                                                              This method is used to 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 Sync differentiates this method from its Async counterpart - .textAsync(). Unlike the Async counterpart, this method is not promised-based.

                                                                                                                                                              a. Set Text Content

                                                                                                                                                              Syntax

                                                                                                                                                              // Set text content of an element
                                                                                                                                                              $(el).textSync(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).textSync(text);

                                                                                                                                                              b. Get Text Content

                                                                                                                                                              Syntax

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

                                                                                                                                                              Return

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

                                                                                                                                                              Usage

                                                                                                                                                              Get an element's text content.

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

                                                                                                                                                              Static Usage

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

                                                                                                                                                              Import

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

                                                                                                                                                              Syntax

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