Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

104
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda