JSFiddle - React, Tailwind, and code Playground
by Nick Craver
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/dot-luv/jquery-ui.css">
<p id="p1" ></p>
<div id="div1">
<p id="p2"></p>
</div>
<p id="p3"></p>
JavaScript
(function($) {
$.fn.isBefore = function(elem) {
if(typeof(elem) == "string") elem = $(elem);
return this.add(elem).index(elem) > 0;
}
})(jQuery)
alert($("#p1").isBefore($("#p2"))); // == true
alert($("#p3").isBefore($("#p2"))); // == false
alert($("#p1").isBefore($("#p3"))); // == true
alert($("#p1").isBefore("#p2")); // == true
alert($("#p3").isBefore("#p2")); // == false
alert($("#p1").isBefore("#p3")); // == true