3

i want to check the style Tag if a classname exist or not.

if ($("head > style:eq(2)").hasClass('className')) 
{
  alert('yes');
}
djot
  • 2,952
  • 4
  • 19
  • 28
Peter
  • 549
  • 3
  • 7
  • 19

2 Answers2

6

You could access the document.styleSheets object:

see the all way in this answer

get CSS rule's percentage value in jQuery

<script>
    var rules = document.styleSheets[0].rules || document.styleSheets[0].cssRules;
    for (var i=0; rules.length; i++) {
        var rule = rules[i];
        if (rule.selectorText.toLowerCase() == ".classname") {
            alert('found!!');
        }
    }
</script>
Community
  • 1
  • 1
Haim Evgi
  • 123,187
  • 45
  • 217
  • 223
0

Another version, same thing, only difference is that sometimes for me selectorText is not defined

var rules = document.styleSheets[0].rules || document.styleSheets[0].cssRules;
for (var i in rules) 
{
    if (typeof rules[i]['selectorText'] != 'undefined' && rules[i]['selectorText'].indexOf("fbconnect_button") >= 0) 
    {
        alert('found!!');
    }
}
Purefan
  • 1,498
  • 24
  • 44