Skip to content

Instantly share code, notes, and snippets.

@AdamTReineke
Created September 25, 2014 01:28
Show Gist options
  • Save AdamTReineke/c05cb0c9fd1cf8b15e78 to your computer and use it in GitHub Desktop.
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.
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);
}
@AdamTReineke
Copy link
Author

Example of contents of nodeCollection: http://i.imgur.com/VVAL7zA.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment