Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get index vanilla js

function index(el) {
  if (!el) return -1;
  var i = 0;
  do {
    i++;
  } while (el = el.previousElementSibling);
  return i;
}
 
PREVIOUS NEXT
Tagged: #index #vanilla #js
ADD COMMENT
Topic
Name
7+5 =