Is there a function in vanilla JS (i.e. not JQuery etc) to determine the activeElement‘s child number?
I’m currently using this code, but I’d prefer to use selCell = document.activeElement.childNumber; (for example) rather than looping through the parent:
for(var j = 0; cell = document.activeElement.parentNode.cells[j]; j++)
if(cell == document.activeElement)
selCell = j;
If any clarification is needed (such as HTML context), ask away!
Thanks a lot!
Table cells keep their own index…
For other element types, a common solution is to start at the current element, and iterate through previous siblings, incrementing a counter every time an element is encountered.