0

Example: the class was Paragraph__P2Short--18r8zx8 styles__DateUpdated--7vi2vd kYkeUS after an hour it changed to Paragraph__P2Short--vgyzhi styles__DateUpdated--6ztczv fQPIAt. How do I find such classes?

I tried document.getElementsByClassName("") but the class is constantly changing, but the styles__DateUpdated does not change in the class

  • The website designer likely dynamically generates the name to prevent people from doing what you are trying to do. However, there are ways to still reliably access the element based on it's location within the HTML markup. In particular, you could try XPATH or the children of another element or class that isn't changing. Look at the HTML hierarchy and figure out what _isn't changing_ and then you can identify the element you are looking for. If `styles__DateUpdated` is always in the classname, you could use a regex. https://stackoverflow.com/questions/13775282/search-for-div-classes-with-regex – h0r53 Jul 11 '23 at 14:38
  • Who or what is updating the class name? – Bergi Jul 11 '23 at 14:43
  • @h0r53 that looks like its standard output from a CSS module compiler. – Andy Jul 11 '23 at 14:46

1 Answers1

1

You might try a CSS selector with .querySelectorAll, like:

const elements = document.querySelectorAll('[class*="styles__DateUpdated--"]');

It will givve you all elements containing the string "styles__DateUpdated--" inside the class attribute. For sure you might have to go deeper to filter down to what you need...

boppy
  • 1,753
  • 12
  • 10