Created
January 2, 2014 14:02
-
-
Save xuncheng/8219581 to your computer and use it in GitHub Desktop.
Find the next or the previous instance for a given selected range
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
jQuery.fn.elementAfter = function(other) { | |
for(i = 0; i < this.length - 1; i++) { | |
if (this[i]() == other) { | |
return jQuery(this[i + 1]()); | |
} | |
} | |
}; | |
jQuery.fn.elementBefore = function(other) { | |
if (this.length > 0) { | |
for(i = 1; i < this.length; i++) { | |
if (this[i]() == other) { | |
return jQuery(this[i - 1]()); | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment