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

                                                                                                                                                          .prependToAsync()

                                                                                                                                                          This method is used to asynchronously prepend matched elements to target elements.

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

                                                                                                                                                          Syntax

                                                                                                                                                          await $(el).prependToAsync(target);

                                                                                                                                                          Parameters

                                                                                                                                                          • target: String|Element - A CSS selector of the element, or the element itself Element, to prepend to.

                                                                                                                                                          Return

                                                                                                                                                          • this - The Play UI instance.

                                                                                                                                                          Usage

                                                                                                                                                          Prepend some dynamically-created nodes to document body.

                                                                                                                                                          $('<h1>Playful people!</h1>').prependToAsync(document.body);

                                                                                                                                                          Prepend an existing div to multiple targets. The div is cloned into all targets except the last target.

                                                                                                                                                          let div = document.querySelector('div');
                                                                                                                                                          $(div).prependToAsync('.multiple');

                                                                                                                                                          Static Usage

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

                                                                                                                                                          Import

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

                                                                                                                                                          Syntax

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