Skip to content

Instantly share code, notes, and snippets.

@galvez
Forked from quirkey/jquery.or.js
Created March 4, 2010 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galvez/322261 to your computer and use it in GitHub Desktop.
Save galvez/322261 to your computer and use it in GitHub Desktop.
// jQuery.fn.or
//
// $('.dont-exist').or('.does-exist') //=> [.does-exist];
// $('.does-exist').or('.dont-exist') //=> [.does-exist];
$.fn.extend({
or: function(selector, context) {
if ($(this).length > 0) {
return $(this);
} else {
context = context || $(this).context;
return $(selector, context);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment