-
-
Save nextend/3d2422d8ba7f24257917e702de762565 to your computer and use it in GitHub Desktop.
Compare DOM tree order of elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/questions/3860351/relative-position-in-dom-of-elements-in-jquery | |
// What this does is .add() the additional element (or selector) | |
// (which jQuery keeps in document order) and then checks if it's the second of the two. | |
(function($) { | |
$.fn.isBefore = function(elem) { | |
if(typeof(elem) == "string") elem = $(elem); | |
return this.add(elem).index(elem) > 0; | |
} | |
})(jQuery) | |
$("#p1").isBefore("#p2"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment