Skip to the content.

$.fn.index([selector])

Return the position of an element relative to a set of siblings or another collection. Returns -1 if no match is found.

Signatures

index(selector?: Selector): number;

Parameters

Returns

The zero-based position, or -1 if no match is found.

Examples

import $ from "dabbyjs";
import "dabbyjs/traversal/index/index";

// Position of the active list item among its siblings
const position = $("li.active").index();
import $ from "dabbyjs";
import "dabbyjs/traversal/index/index";

// Carousel: which dot was clicked?
$(".carousel-dot").on("click", function () {
    const i = $(".carousel-dot").index(this);
    showSlide(i);
});
import $ from "dabbyjs";
import "dabbyjs/traversal/index/index";

// Find the active item's position within a filtered set
const i = $("li").index("li.active");

See also