Skip to content

getIndex

Mike Byrne edited this page Jan 25, 2022 · 2 revisions

description

Returns the index of a node in a nodeList

requires

  • nothing

parameters

  • node - required - what you want to find the index of
  • nodeList - optional - what you want to find the index in, if none specified it looks at the node's parent

returns

  • index of node

example usage:

var index = getIndex(el);
var links = document.querySelectorAll('a');
var clickedLink = event.target;
var index = getIndex(clickedLink, links);