Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Created May 26, 2016 02:25
Show Gist options
  • Save michaellwest/f485b07882436ddaf053a8ee09021e3f to your computer and use it in GitHub Desktop.
Save michaellwest/f485b07882436ddaf053a8ee09021e3f to your computer and use it in GitHub Desktop.
jQuery functions to move elements up and down.
/* http://stackoverflow.com/questions/11098257/jquery-move-dom-element-inside-parent */
$.fn.moveUp = function() {
$.each(this, function() {
$(this).after($(this).prev());
});
};
$.fn.moveDown = function() {
$.each(this, function() {
$(this).before($(this).next());
});
};
$("div:eq(2)").moveUp(); //Would move hello 3 up
$("div:eq(0)").moveDown(); //Would move hello 1 down
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment