Created
November 17, 2014 21:46
-
-
Save c-kick/d42ea03d5fc1e6e9baa4 to your computer and use it in GitHub Desktop.
jQuery selector: At least x elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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