Skip to content

Instantly share code, notes, and snippets.

@c-kick
Created November 17, 2014 21:46
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 c-kick/d42ea03d5fc1e6e9baa4 to your computer and use it in GitHub Desktop.
Save c-kick/d42ea03d5fc1e6e9baa4 to your computer and use it in GitHub Desktop.
jQuery selector: At least x elements
//count elements, return jQuery object if more than specified, else return empty object to 'stop' chaining
// usage: $('myElement').atLeast(2).fadeOut(); fadeOut will only execute on elements when 2 or more have been found
(function ($) {
"use strict";
$.fn.atLeast = function (count) {
if (this.length >= count) {
//return the objects
return this;
} else {
//return empty jquery object to 'break' the chain
return $();
}
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment