JS: Get the index of an element