Skip to content

Instantly share code, notes, and snippets.

@DavidSouther
Created March 8, 2012 16:09
Show Gist options
  • Save DavidSouther/2001793 to your computer and use it in GitHub Desktop.
Save DavidSouther/2001793 to your computer and use it in GitHub Desktop.
/**
* Calculate the specificity of a selectorList (the sum of the count of
* matching attributes).
*/
var specificity = function(selectorList) {
var spec = 0;
goog.array.forEach(selectorList, function(selector){
spec += selector.hierarchy?1:0;
spec += selector.type?1:0;
spec += selector.id?1:0;
spec += selector.attributes.length;
});
return spec;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment