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

140
Visualizações
Document.QuerySelector to fill a unique value with prepend and append

I am trying to use a JS code to fill up elements with their already filled up values as desribed in the table link image below:

enter image description here For this code below, what modifcation will be required to get the desired final value?

var data = document.querySelectorAll("[id^='1253']").forEach(x => x.value
if( data > 0){
  var result = '(' + data + ')'
  document.querySelectorAll("[id^='1253']").forEach(x => x.value = result)
}
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Not sure why you call querySelectorAll twice or what data is for:

document.querySelectorAll("[id^='1253']")
  .forEach(o => {
    if (o.value && !isNaN(o.value) && o.value < 0.9) o.value = `(${o.value})`;
  });
<div><input id="1253~blah1" value="0.1" /></div>
<div><input id="1253~blah2" value="0.2" /></div>
<div><input id="1253~blah3" value="" /></div>
<div><input id="1253~blah4" value="0.9" /></div>
<div><input id="1253~blah5" value="11.2" /></div>

about 4 years ago · Juan Pablo Isaza Relatório

0

User innerText instead of value when setting the result in your elements. value is an html property and doesn't necessarily mean what's viewed on the screen.

if( data > 0) {
  var result = '(' + data + ')'
  document.querySelectorAll("[id^='1253']").forEach(x => x.innerText = result)
}
about 4 years ago · Juan Pablo Isaza Relatório

0

document.querySelectorAll("[id^='1253']")
  .forEach(o => {
    if (o.value && !isNaN(o.value) && o.value < 0.9) o.value = `(${o.value})`;
  });

This is the code which solved my query. Thank you everyone.

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