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

199
Views
Put JavaScript value inside HTML

How to put JavaScript value inside HTML ?

I am trying to put JavaScript value inside HTML like below.

<p>
    Check your Credit Score <a href="http://someaddress.com?first_name='+ first_name +'" target="_blank">Here</a>
</p>
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can do like this

<p>
 Check your Credit Score
<a href="http://someaddress.com?first_name='+ first_name +'" target="_blank"
 >Here</a >
</p>

 <script type="text/javascript">
   const a = document.querySelector('a');

   const first_name = 'John';

   a.href = 'http://someaddress.com?first_name=' + first_name ;
 
 </script>
about 4 years ago · Juan Pablo Isaza Report

0

do this if you want to change the link document.querySelector('a').href = "http://someaddress.com?first_name=" + first_name;

about 4 years ago · Juan Pablo Isaza Report

0

To achieve the results, you can make use of document.getElementById('').href property:

HTML (added the id attribute to the <a> tag):

<p>
  Check your Credit Score <a id="link" href="" target="_blank">Here</a>
</p>

JavaScript:

window.onload = function() {
    var first_name = 'Peter';
  document.getElementById('link').href = 'http://someaddress.com?first_name='+ first_name;
  
  // debug your results
  console.log(document.getElementById('link').href);
}

Here is the JSFiddle

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!