Skip to content

Instantly share code, notes, and snippets.

@bkeepers
Forked from quirkey/jquery.or.js
Created March 6, 2010 13:56
Show Gist options
  • Save bkeepers/323698 to your computer and use it in GitHub Desktop.
Save bkeepers/323698 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