get li index within a ul not with jquery!
I'm using dhtmlgoodies drag-drop-folder-tree and when you click save you get the
id-parentid, id-parentid, etc...
开发者_运维技巧i want to have the li index within it's ul so i can tell their order as well - so i want it to look like this:
id-parentid-orderid, id-parentid-orderid, ETC...
their code is not jquery (i know how to do it in jquery with the index()
but it is pure JS
how do i get the index of an element within his parent?
You'll have to write your own index function ;)
e.g. lets say that liNode is an <li>
node within an <ul>
function index(array, element) {
for (var i = 0; i < array.length; i++) {
if (array[i] == element) return i;
i++;
}
return -1;
}
var allLiNodes = liNode.parentNode.childNodes;
var myIndex = index(allLiNodes, liNode);
精彩评论