Example:
How do I check if div #test has any of .a1
.a2
.a3
.a4
.a5
classes? With only one if-statment...
<div id="test" class="a1 a2 a5"></div>
Get a CSS Property Value You can get the computed value of an element's CSS property by simply passing the property name as a parameter to the css() method. Here's the basic syntax: $(selector). css("propertyName");
To find the class of clicked element, we use this. className property. The className property is used to set or return the value of an element's class attribute. Using this property, the user can change the class of an element to the desired class.
You could use the jQuery is
function, checking all the classes that you want match.
$("#test").is(".a1,.a2,.a3,.a4,.a5")
You can use the hasClass function.
var test = $('#test'); if(test.hasClass('a1') || test.hasClass('a2') || test.hasClass('a3') ...) { ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With