Skip to content

Instantly share code, notes, and snippets.

@twiss
Created July 11, 2011 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save twiss/1076510 to your computer and use it in GitHub Desktop.
Save twiss/1076510 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
* doesn't work yet (tested with 1.1.5)
*/
Slick.definePseudo('has-n-children', function(arg) {
var childrenLen = Slick.search(this, '> *').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