Let us suppose I have this markup
First
Hi
Hello
Second
Rocket's solution works fine if sel is a real selector, if you pass a jquery object though, it won't work.
If you want a plugin that works with both selectors and jquery objects, just use my slightly modified version instead:
(function($) {
$.fn.isAfter = function(sel){
return this.prevAll().filter(sel).length !== 0;
};
$.fn.isBefore= function(sel){
return this.nextAll().filter(sel).length !== 0;
};
})(jQuery);
Kudos to Rocket for the original solution.