Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
What's the best way to test\validate a css selection string via javascript?

The first answer that popped into my head was: "using querySelector method wrapped into a try - catch error handler" Something like this:

const cssString = '* > a[href *= "://adclick"]';
try {
    document.querySelector(cssString);
    console.log('Valid')
} catch {
    console.log('Not Valid')
}

I was puzzled when I found that removing either the closing square bracket or the closing double quote the syntax was still correct (the exception is not raised). Is there a reason for this? I mean: how does the syntax be correct without one or both of the above characters? Is there an efficient and safe way to test these syntaxes?

Thanks

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!