$.fn.reverse =
function () { return this.pushStack(this.get().reverse(), arguments);};
// create two new functions: prevALL and nextALL.
$.each([
'prev', 'next'], function (unusedIndex, name) {$.fn[name +
'ALL'] = function (matchExpr) { // get all the elements in the body, including the body. var $all = $('body').find('*').andSelf(); // slice the $all object according to which way we're looking$all = (name ==
'prev')? $all.slice(0, $all.index(
this)).reverse(): $all.slice($all.index(
this) + 1);
// filter the matches if specified if (matchExpr) $all = $all.filter(matchExpr); return $all;};
});