How can I set css selector that checks for start of name of a class?

for example "styles_verificationIcon___X7KO". I want to find element by class that starts with "styles_verificationIcon". This does not work: document.querySelector("[class^=styles_verificationIcon]");
12 Replies
extended-salmon
extended-salmon3y ago
Hi @Casper have you tried adding quotes around styles_verificationIcon? There might be an issue with omitting quotes when class is not alphanumeric
correct-apricot
correct-apricotOP3y ago
I have tried ' ', " " does not work
extended-salmon
extended-salmon3y ago
The selector looks ok to me, have you tried testing it in chrome devtools?
correct-apricot
correct-apricotOP3y ago
No description
correct-apricot
correct-apricotOP3y ago
Trustpilot
Diba Billån er bedømt "Fremragende" med 4,8 / 5 på Trustpilot
Er du enig i TrustScoren for Diba Billån? Del din mening i dag, og find ud af, hvad 665 kunder allerede har sagt.
correct-apricot
correct-apricotOP3y ago
I am trying to get
No description
correct-apricot
correct-apricotOP3y ago
I am using chrome dev tools
extended-salmon
extended-salmon3y ago
Ah yes, this is because the class attribute doesn't actually start with styles_verificationIcon, there are other classes before
correct-apricot
correct-apricotOP3y ago
what can I do instead?
extended-salmon
extended-salmon3y ago
I would try using div[class*="styles_verificationIcon"] this will select any element where class contains styles_verificationIcon
correct-apricot
correct-apricotOP3y ago
thank you very much it works flawless
correct-apricot
correct-apricotOP3y ago
No description

Did you find this page helpful?