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

109
Vistas
How to use document.querySelector to search for a pattern match and fill value

I have an element in an webpage

id="1253~~0~0~506~13501157_txtValue"

I want to search all element matches beginning with this value 1253 and it should be filled up the value test

For this I am using this following code but it isnt working

document.querySelector('[id^ ='1253']').value = test

Please guide me as to where I am going wrong Thanks in advance. -Vicky.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your selector is good but you should either use double quotes (") and single quotes (') or escape your inner single quotes.

Also, if test is not a variable you should surround it with quotes : "test".

As pointed out by @adiga, if you want to match all elements whose id begins with "1253", you should use querySelectorAll() and loop through the results.

document.querySelector("[id^='1253']").value = "test";
//the following line is equivalent
//document.querySelector('[id^=\'1253\']').value = "test";
<input type="text" id="1253~~0~0~506~13501157_txtValue" />

about 4 years ago · Juan Pablo Isaza Denunciar
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