Created
September 25, 2014 01:28
-
-
Save AdamTReineke/c05cb0c9fd1cf8b15e78 to your computer and use it in GitHub Desktop.
Instrument appendChild to build an array of paths from the root to the added child.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nodeCollection = []; | |
var nodeGetNodeName = function (node) { | |
if (node.parentElement) { | |
return nodeGetNodeName(node.parentElement) + " > " + node.nodeName; | |
} | |
return node.nodeName; | |
} | |
Node.prototype._appendChild = Node.prototype.appendChild; | |
Node.prototype.appendChild = function () { | |
nodeCollection.push(nodeGetNodeName(this) + " > " | |
+ ((arguments[0] instanceof String) | |
? "new " + arguments[0] | |
: arguments[0].nodeName + " and children")); | |
return Node.prototype._appendChild.apply(this, arguments); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of contents of nodeCollection: http://i.imgur.com/VVAL7zA.png