Trying to perform action when <figure>
with class .woocommerce-product-gallery__wrapper
has another class alongside it – .test
.
This .test
class is placed there by another JavaScript powered button that’s toggling the class in and out. So this event would need to continue listening.
if($( ".woocommerce-product-gallery__wrapper" ).hasClass( "test" )){
console.log('Hello');
// I have the 'hidden' class
};
I feel this is something super easy and as a JS noob, I’m doing something super stupid/missing something.
2
Answers
Try:
Consider the following.
This will select all elements with both classes,
woocommerce-product-gallery__wrapper
andtest
.You can also do something like.
This will iterate each element with class
woocommerce-product-gallery__wrapper
and check if it has thetest
class. This is helpful when you want to perform an action on just those elements.You can also use
.filter()
like this.There are lots of ways to find a specific element.