Closed keeganstreet closed 8 years ago
Specificity Calculator now exposes a compare function. This function accepts two CSS selectors, a and b.
compare
a
b
-1
1
0
SPECIFICITY.compare('div', '.active'); // -1 SPECIFICITY.compare('#main', 'div'); // 1 SPECIFICITY.compare('span', 'div'); // 0
You can pass the SPECIFICITY.compare function to Array.prototype.sort to sort an array of CSS selectors by specificity.
SPECIFICITY.compare
Array.prototype.sort
Comparing two selectors
Specificity Calculator now exposes a
compare
function. This function accepts two CSS selectors,a
andb
.-1
ifa
has a lower specificity thanb
1
ifa
has a higher specificity thanb
0
ifa
has the same specificity thanb
Ordering an array of selectors by specificity
You can pass the
SPECIFICITY.compare
function toArray.prototype.sort
to sort an array of CSS selectors by specificity.