`
function fetchImage() {
const options = {
method: ‘GET’,
headers: {
‘x-rapidapi-key’: secretkey,
‘x-rapidapi-host’: ‘nfl-api-data.p.rapidapi.com’
}
};
fetch('https://nfl-api-data.p.rapidapi.com/nfl-ath-img?id=3139477', options)
.then(response => response.json())
.then(response => {
const data = response.image.href;
const blob = new Blob([data], {type: 'image/png' });
let container = document.getElementById('image-container'); /* Error is here */
let imageElement = document.createElement('img');
imageElement.src = data;
container.appendChild(imageElement);
})
.catch(err => console.error(err));
}
fetchImage();`
This is the error I was getting:
ReferenceError: document is not defined
at c:AnalyticsWebsitejsindex.js:29:25
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {stack: ‘ReferenceError: document is not defined
a…ions (node:internal/process/task_queues:95:5)’, message: ‘document is not defined’}
I tried taking the line of code with document.getElementId(‘image-container’) out of the function because I thought maybe that had something to do with it but then my code just stopped working. By the way the code works and prints the image that I wanted from the api, it’s just I’m looking to figure out why I’m getting that error.
Jace Johnson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.