Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery - How to check if classname exists

Tags:

jquery

css

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

if ($("head > style:eq(2)").hasClass('className')) 
{
  alert('yes');
}
like image 812
Peter Avatar asked Nov 26 '25 18:11

Peter


1 Answers

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>
like image 129
Haim Evgi Avatar answered Nov 28 '25 16:11

Haim Evgi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!