There are ways to query the rules from the loaded stylesheets:
jquery - Listing known CSS classes using Javascript - Stack Overflow[
^]
function listAllCssSelectors(){
var result = [];
var sheets = document.styleSheets, sheetCount = sheets.length;
for(var i = 0; i < sheetCount; i++) {
try {
var rules = document.styleSheets[i].cssRules, ruleCount = rules.length;
for (var j = 0; j < ruleCount; j++) {
var selector = rules[j].selectorText;
if (selector) {
result.push(selector);
}
}
}
catch (e) {
}
}
return result;
}
HOWEVER, if any stylesheet is loaded from a different domain - for example, if you're using a CDN - then you can't access its rules. The
try..catch
block above will swallow the exception, but the method won't return any rules for those external stylesheets.
For example, running the method on CodeProject returns a grand total of three selectors, because most of the stylesheets are hosted on a different domain.
As there are only 263 Glyphicons in the current version of Bootstrap, it would probably be easier to create a static list.