Hello coders i have the following script: http://jsfiddle.net/UqDJk/241/
I want the moveUp function to move the list up one place..
var moveUp = function (up, direction) {
var btn = up.target,
li = btn.parentNode;
li.insertBefore(li[1].nextSibling)
}
Is there a simple way to do this? P.s. please pure javascript.
I think you want:
But note that
li.previousSiblingwill benullfor the first element, in which case it will appended to the list. So you have to add a check to avoid moving the first element:Problems in your code:
mdn insertBefore.li[1]tries to access property1ofli, which does not exist sinceliis a DOM element object.