Skip to the content.

$.fn.eq(index)

Reduce the collection to the single element at the given index. Negative indices count back from the end of the collection.

Signatures

eq(index: number): this;

Parameters

Returns

A new Dabby collection containing the single element at the requested index. If the index is out of range, the returned collection is empty.

Examples

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

// Highlight the third list item
$("li").eq(2).addClass("highlighted");
import $ from "dabbyjs";
import "dabbyjs/traversal/eq/eq";

// Select the last row of a table
const $lastRow = $("table tr").eq(-1);
import $ from "dabbyjs";
import "dabbyjs/traversal/eq/eq";

// Simple carousel — show the slide for the active dot
$(".carousel-dot").on("click", function () {
    const index = $(".carousel-dot").index(this);
    $(".slide").hide().eq(index).show();
});

See also