Sorting a set of CSS selectors on the basis of specificity
问题 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; } 回答1: From the Selectors spec: A selector's specificity is calculated as follows: count the number of ID selectors in the selector (= a) count the number of class selectors, attributes selectors, and pseudo-classes in the selector (= b) count the number of type selectors and pseudo-elements in the