Skip to content

Commit

Permalink
swap 2 dom elements code
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Sep 20, 2023
1 parent 3362ad8 commit 677ccb2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/js/gui/widgets/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@ Element.prototype.insertChildAtIndex = function(child, index) {
} else {
this.insertBefore(child, this.children[index])
}
};
};

Element.prototype.swap = function (node) {
const parent = this.parentNode;
const sibling = this.nextSibling === node ? this : this.nextSibling;

// Move `this` to before the `node`
node.parentNode.insertBefore(this, node);

// Move `node` to before the sibling of `this`
parent.insertBefore(node, sibling);
};

0 comments on commit 677ccb2

Please sign in to comment.