Dejavu
Dejavu

Reputation: 713

jQuery check if body has prefix

I am trying to run a jQuery function in opencart. I have several pages with a body class like : product-category-20 product-category-50 ...and so on.

What I've tried :

if ($("body").hasClass("common-home, [class*="product-category-"]"){

}

Upvotes: 0

Views: 70

Answers (1)

guest271314
guest271314

Reputation: 1

Try removing double quotes within attribute selector , using .is()

$(function() {
  if ($("body").is("[class*=product-category], .common-home")) {
     alert(true)
   }
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>

<body class="product-category-20 product-category-50 common-home"></body>

Upvotes: 1

Related Questions