You can make a function that does this, for example:
(function($) {
$.fn.isBefore = function(elem) {
if(typeof(elem) == "string") elem = $(elem);
return this.add(elem).index(elem) > 0;
}
})(jQuery)
You can try here , the first line is so that it can also take the selector line directly, for example:
$("#p1").isBefore("#p2");
.add() ( ) ( jQuery ), , .
, , , true, - "" , , , , $("p").isBefore("#p2") true, <p> "" #p2.