Reputation: 11
I'm building an eCommerce site and need to add a class to the body tag if the page contains a specific term, in this case, "Accessories." I've used this code to style the span that it appears in but I would need to wrap the whole page in a class to style certain elements.
$(document).ready(function () {
$("span:contains('Accessories')").addClass("newstyle");
Any suggestions?
Upvotes: 1
Views: 297
Reputation: 781120
Use :has()
to test if the body contains a specific element that contains Accessories
$("body:has(span[itemprop='name'].newaccessories:contains(Accessories))").addClass("newstyle");
Upvotes: 1