I've been playing with this... $.fn.if = function(flag) { return (flag) ? this.pushStack( this ) : this.pushStack( [] ); };
You can then do stuff like: var addEdges = function(selector,opts) { $('.selector) .addClass('selected') .if(opts.page>1) .addClass('more-left') .end() .if(opts.page<opts.num_pages) .addClass('more-right') .end(); } It's overkill, but having if statements in a jQuery chain makes for pleasant reading IMHO. My brain started to hurt when I tried adding ".else()" and also when I started thinking of "if ... else ... end" or things like "if ... else if ... end" and nesting, etc. Anyone got any ideas on how to extend my basic ".if()" ? Guy