0

Is there a way to check the DOM for a class name containing the string "cookie"?, it can be .cookiesaved, .cookie-notice , .cookie-set , whatever as long as it contains the word "cookie" i need it to return true, and must be a class so i cannot use indexOf of the whole html document.

Also I can't use jQuery, so i'm trying to find a way via pure js.

What I'm trying to do is to check if the page has a cookie banner or not basically, and I couldn't come up with a better idea than checking for that class string so far.

Nathan Bernard
  • 189
  • 2
  • 2
  • 9

1 Answers1

1

I guess you are looking for CSS attribute selectors: [class*="cookie"], see MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors. E.g. document.querySelector('[class*="cookie"]') !== null

ingmak
  • 117
  • 1
  • 7