Check if CSS Class exists in StyleSheet using javascript/jQuery
Posted
by
Akhil Sekharan
on Stack Overflow
See other posts from Stack Overflow
or by Akhil Sekharan
Published on 2012-12-19T07:43:20Z
Indexed on
2012/12/19
11:03 UTC
Read the original article
Hit count: 223
Is there a way to check if there is a class named 'some-class-name' in css?
For example, I have:
<style type="text/css">
.box {
position: absolute;
left: 150%;
}
</style>
My intention is to randomly assign a class to a div on certain event:
var classList = []; //Need to populate this array
$('#updateClass').on('click', function() {
$('#resultDiv').attr('class',classList[Math.floor((Math.random()*classList.length)+1)]);
});
Is it possible to check by JS/jQuery whether a class named 'box' exists in the stylesheet?
Thanks.
© Stack Overflow or respective owner