Skip to the content.

$.fn.even()

Reduce the collection to the elements at even indices (0, 2, 4, …). Indices are zero-based, so the first matched element is always included.

Signatures

even(): this;

Parameters

None.

Returns

A new Dabby collection containing the elements at indices 0, 2, 4 and so on.

Examples

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

// Apply a zebra pattern to a table
$("table tbody tr").even().addClass("row-even");
import $ from "dabbyjs";
import "dabbyjs/traversal/even/even";

// Highlight the 1st, 3rd, 5th... item in a list
$(".item").even().addClass("highlighted");

See also