Skip to content

Instantly share code, notes, and snippets.

@boppy
Forked from twiss/slick-has-n-children.js
Last active January 24, 2016 12:30
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 boppy/12f3a43efbb87e4b54e9 to your computer and use it in GitHub Desktop.
Save boppy/12f3a43efbb87e4b54e9 to your computer and use it in GitHub Desktop.
Tries to define :has-n-children([<|>|<=|>=]n)
/* :has-n-children([<|>|<=|>=]n)
* requires Slick
* selects elements with (less/more than (or equal to)) n elements as children
* [2011-07-11] doesn't work yet (tested with 1.1.5)
* [2016-01-24] works now (testet with 1.6); https://jsfiddle.net/ugLaexhc/2/
*/
Slick.definePseudo('has-n-children', function(arg) {
var childrenLen = this.children.length;
var parsedArg = arg.match(/(<|>|<=|>=)?(\d+)/);
switch(parsedArg[1]) {
case '<': return childrenLen < parsedArg[2];
case '<=': return childrenLen <= parsedArg[2];
case '>': return childrenLen > parsedArg[2];
case '>=': return childrenLen >= parsedArg[2];
default: return childrenLen == parsedArg[2];
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment