Skip to content

Instantly share code, notes, and snippets.

@edirpedro
Created July 15, 2015 15:22
Show Gist options
  • Save edirpedro/bf64c4f046437cf50458 to your computer and use it in GitHub Desktop.
Save edirpedro/bf64c4f046437cf50458 to your computer and use it in GitHub Desktop.
Search for the first element found in the objects array passed
/*
* Function findFirst() will search for the first element found in the objects array passed
* $.findFirst('selector', [element, document]);
*/
$.extend({
findFirst: function(selector, objs) {
for (var i in objs) {
var elem = jQuery(selector, objs[i]);
if (elem.length) return elem;
}
return jQuery();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment