Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

119
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda