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

160
Views
How do I take a URL stored in a variable in JS and pass it to HTML file?

I am a beginner so I'm sure this is probably obvious.

I have an API call which finds current news for a location which I have stored in a variable called newsUrl. I wish to show this in my HTML file within a modal.

here is the code for my modal

<div id="newsModal" class="modal">   
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-heading">News</h4>
          <button type="button" class="btn-close"  aria-label="Close"></button>
      </div>
      <div class="modal-body">
          <table class="table table-striped">
    <tbody>
     
        <tr>
          
          <td><p id="txtNews"></p></td>

        </tr>
        
      
     
  </table>
  </div>
        </div>
      </div>

I have tried the following code within my JS file

newsUrl = result['data'][0]['url'];
          newsImage = result['data'][0]['image'];
          newsTitle = result['data'][0]['title'];
          

          newsLink = ('<a href="//'+newsUrl+'" target=_blank ></a>');
             
          $('#txtNews').html(newsLink);

No errors in the console.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try to use: $('#txtNews').append(newsLink);

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!