Last active
August 29, 2015 14:06
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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