Skip to content

Instantly share code, notes, and snippets.

@scottoffen
Last active August 29, 2015 14:06
Show Gist options
  • Save scottoffen/13f4054da738c6028104 to your computer and use it in GitHub Desktop.
Save scottoffen/13f4054da738c6028104 to your computer and use it in GitHub Desktop.
jQuery namespaced function to determine if a css selector is defined in any attached stylesheet
(function ($)
{
$.styleExists = function (s)
{
var exists = false;
var stylesheets = document.styleSheets;
for (var sx = 0, sl = stylesheets.length; sx < sl; sx += 1)
{
var sheetclasses = stylesheets[sx].rules || document.styleSheets[sx].cssRules;
for (var cx = 0, cl = sheetclasses.length; cx < cl; cx += 1)
{
if (sheetclasses[cx].selectorText == s)
{
exists = true;
break;
}
}
}
return exists;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment