Skip to content

Instantly share code, notes, and snippets.

@joews
Created June 13, 2014 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joews/3352a472fcc7372b7e9f to your computer and use it in GitHub Desktop.
Save joews/3352a472fcc7372b7e9f to your computer and use it in GitHub Desktop.
D3.js bring to front
// Credit Christopher Chiche & Clemens Tolboom
// - http://stackoverflow.com/a/14426477/2806996
d3.selection.prototype.moveToFront = function() {
return this.each(function(){
this.parentNode.appendChild(this);
});
};
d3.selection.prototype.moveToBack = function() {
return this.each(function() {
var firstChild = this.parentNode.firstChild;
if (firstChild) {
this.parentNode.insertBefore(this, firstChild);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment