Bug 26525 - Implement swapNode
Summary: Implement swapNode
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Enhancement
Assignee: Nobody
URL: http://msdn.microsoft.com/en-us/libra...
Keywords:
Depends on:
Blocks:
 
Reported: 2009-06-18 15:55 PDT by Erik Arvidsson
Modified: 2022-08-11 04:49 PDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Arvidsson 2009-06-18 15:55:17 PDT
Swapping the place of two nodes in a document is not that hard but it requires more code than one would expect. It would be nice if we could add this MS extension.

Here is a pure JS implementation:

Node.prototype.swapNode = function(that) {
  var nextSibling = this.nextSibling;
  if (nextSibling == that) {
    that.swapNode(this);
    return;
  }
  var thisParent = this.parentNode;
  that.parentNode.replaceChild(this, that);
  thisParent.insertBefore(that, nextSibling);
};
Comment 1 at 2011-11-22 00:58:33 PST
They got you covered baby, 
check out
document.documentFragment

Here's a handy link to see if it will 
meet your needs.
http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-1004215813


That node swap is kooky man, 
can't somebody dump this ticket?
Comment 2 Ahmad Saleem 2022-08-11 04:49:22 PDT
swapNode was IE only and it was changed with "replaceChild".

https://quirksmode.org/dom/core/

Even below test page - give "swapNode gave an error" across all browsers (Chrome Canary 106, Firefox Nightly 105 and Safari 15.6).

https://quirksmode.org/dom/core/microsoft.html

Only found this reference about it in Webkit Github:

https://github.com/WebKit/WebKit/blob/8afe31a018b11741abdf9b4d5bb973d7c1d9ff05/JSTests/ChakraCore/test/Basics/DomProperties.js#L3414

I am going to mark this as "RESOLVED WONTFIX". If I am incorrect, please mark accordingly. Thanks!