You can add something simple to cheerio like this:
var cheerio = require('cheerio');
cheerio.prototype.odd = function() {
var odds = [];
this.each(function(index, item) {
if (index % 2 == 1) {
odds.push(item);
}
});
return cheerio(odds);
}
var $ = cheerio.load("<div>0</div><div>1</div><div>2</div><div>3</div><div>4</div>");
$("div").odd().each(function() {
console.log($(this).text());
});
Yes, it doesn't match jquery exactly, but it's similar to how cheerio deals with jquery's :eq(n)
selector.