EvoToolkit - v3.7.2 (Changelog)

getIndex

Returns the index of an element relative to its position within its parent.

Source

Contributors

Luke Harrison

Usage

When importing EvoToolkit directly as a compiled .js file without a build step, you can still use these tools through the global EvoToolkit object.

window.evotoolkit.tools.toolName()
import fireEvent from './../../../node_modules/evotoolkit/src/js/tools/getIndex.js';

// Activate content element matching a specific tab
const myTab = block.querySelectorAll('.js-my-tab');
const content = block.querySelectorAll('.c-tabs__content');
content[this.getIndex(myTab)].classList.add('is-active');