I am working with wordpress and I have to display a menu based on a product category but it goes by term and there is no way for me to add a class. So I have term-maincat-subcat as the class and the subcat changes depending on where your at but the main cat stays the same as it is the brand. I was looking into the jQuery wildcards and there is a way to select an element with a certain string in a class. How would I go about running a conditional to check if it has that string in the class. Here’s what I’ve got…
if($('body').is('body[class~="brand"]')) {
$('.brand-cat-nav').show();
}
The above doesn’t seems to work and like I said, unfortunately, there is no way of adding a straight “brand” class to it to make this a little easier with being able to just use .hasClass(). Any suggestions?
PS: the class that it’s outputting to the body is some thing to likes of “term-maincat-subcat”.
You can try this:
This filters the
bodywith a class name that starts with ‘brand’.If you want to test if
bodyhas a class containing ‘brand’ useclass*="brand"as filter instead.