DOM Elements API

$.swap()

async

Swaps the positions of two DOM elements.

  • Accepts two arguments, both as DOM elements.
  • Returns an array of DOM elements that have been swapped with one another.
    Returns false if at least one DOM element cannot be swapped.
  • It is not necessary to wait for the method to be executed using await if not needed.
Example:
await $.swap($('div'), $('span'));
// Swaps the <div> element with the <span> element.
// [<div>, <span>]

await $.swap($('div'), $('span.classDoesNotExist'));
// The <span> element was not found, making it impossible to swap positions.
// false