How can a set of CSS selectors be sorted on the basis of CSS specificity in a JS function?
function SortByCssSpecificity(input_array_of_css_selectors) {
...
return sorted_array_of_css_selectors;
}
How can a set of CSS selectors be sorted on the basis of CSS specificity in a JS function?
function SortByCssSpecificity(input_array_of_css_selectors) {
...
return sorted_array_of_css_selectors;
}
From the Selectors level 3 spec:
(Selectors level 4, published after this answer, adds another layer of complexity to specificity thanks to the introduction of some new selectors that is currently outside this answer's scope.)
Here's a pseudocode implementation to get you started, it is nowhere near perfect but I hope it's a reasonable starting point: