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

201
Views
How do I store JSON url to JS variable and load the video on HTML page?

I'm new to HTML, JS and JSON and I'm having some trouble loading a video url from JSON file. I downloaded the JSON file from https://ign-apis.herokuapp.com/videos?startIndex=30&count=5. When I use console.log(data.data[0].assets[4].url), it displays the correct url and I'm able to view the video on the new window but I can't seem to get it to display and run on my html page.

index.html

<video width="1100px" height="555px" poster id="firstthumbnail">
    <source src id="firstvid" type="video/mp4">    <!--First video-->
</video>
<script src="script.js"></script>

script.js

fetch("videos.json")
.then(response => response.json())
.then(data => {
    console.log(data)
    document.querySelector("#firstvid").innerText = data.data[0].assets[4].url
    document.querySelector("#firstthumbnail").innerText = data.data[0].thumbnails[0].url
})
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

the innerText property of an element decides what is displayed as text in the element. Instead of using .innerText, use .src.

about 4 years ago · Juan Pablo Isaza Report

0

You must set src attribute to your video tag. Try this:

document.getElementById("firstvid").setAttribute("src", data.data[0].assets[4].url);
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!