Skip to content

getIndex

Mike Byrne edited this page Mar 7, 2018 · 2 revisions

getIndex

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);

Clone this wiki locally