I have a server-side treeview control that I want to be able to move selected nodes up or down within a parent. I can do this rather easily in server-side code but it generates post backs each time. So that led me to try a Javascript solution.
I'm not a DOM expert but I see the possibilities here. However I can't get the code to work properly.
trvt1 represents the first node under the parent, trvt4 represents the fourth. This code below moves the 4th behind the 1st node but I want to insert it before. I inserted a spacer because if I didn't insertBefore puts the nodes on the same line.
If someone can point me in the right direction that would be great.
I'm not a DOM expert but I see the possibilities here. However I can't get the code to work properly.
trvt1 represents the first node under the parent, trvt4 represents the fourth. This code below moves the 4th behind the 1st node but I want to insert it before. I inserted a spacer because if I didn't insertBefore puts the nodes on the same line.
Code:
function nodeUp()
{
/* this inserts an existing node AFTER the target node then rearranges
* the ordering of the node */
var spacer = document.createElement('br');
document.getElementById('trvt1').appendChild(spacer);
var testing = document.getElementById('trvt1').insertBefore(document.getElementById('trvt4'));
}
If someone can point me in the right direction that would be great.