Let us suppose I have this markup
First
Hi
Hello
Second
To see if an element is after another, you can use prev() or prevAll() to get the previous element(s), and see if it matches.
And to see if an element is before another, you can use next() or nextAll() to get the next element(s), and see if it matches.
$.fn.isAfter = function(sel){
return this.prevAll(sel).length !== 0;
}
$.fn.isBefore= function(sel){
return this.nextAll(sel).length !== 0;
}
DEMO: http://jsfiddle.net/bk4k7/