Javascript – Finding DOM node index


I want find the index of a given DOM node. It's like the inverse of doing


I want to instead extract the value of K given that I already have the reference to the child node and the parent node. How do I do this?

Best Solution

The shortest possible way, without any frameworks, in all versions of Safari, FireFox, Chrome and IE >= 9:

var i =, someChildEl);