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

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

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