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

139
Views
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 answers
Answer question

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 Report

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 Report

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 Report
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!