Reputation: 549
i want to check the style Tag if a classname exist or not.
if ($("head > style:eq(2)").hasClass('className'))
{
alert('yes');
}
Upvotes: 3
Views: 2360
Reputation: 1506
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!!');
}
}
Upvotes: 0
Reputation: 125674
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>
Upvotes: 6