Use the onClick event to call the getIndex function (no jQuery, just vanilla javascript):
onClick = "getIndex(this);" function getIndex(node) { var childs = node.parentNode.childNodes; for (i = 0; i < childs.length; i++) { if (node == childs[i]) break; } return i; }
The index starts at 0! To get started with 1: return i+1
source share