Skip to content

Instantly share code, notes, and snippets.

@mvrilo
Created November 23, 2012 15:21
Show Gist options
  • Save mvrilo/4136105 to your computer and use it in GitHub Desktop.
Save mvrilo/4136105 to your computer and use it in GitHub Desktop.
function childFind(selector, which) {
if (!this || !this.length) return $([]);
which = (which || 'previous') + 'Sibling';
var element = this[0][which];
while (element && (element.nodeType !== 1 || !$(element).is(selector))) element = element[which];
return $(element);
}
$.fn.prevFind = function(selector) { return childFind.call(this, selector); };
$.fn.nextFind = function(selector) { return childFind.call(this, selector, 'next'); };
@mvrilo
Copy link
Author

mvrilo commented Nov 28, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment