#addEventListener

3 messages · Page 1 of 1 (latest)

last ibex
#

const randomNumber = Math.ceil(Math.random() * 83);
const button = document.querySelector("getRandomCharacter");
button.addEventListener("click", (e) => {
e.preventDefault();
fetch(https://swapi.dev/api/people/${randomNumber})
.then((response) => response.json())
.then((character) => {
console.log(character);
});
});

I am attempting to fetch data after I press my button. I am getting an uncaught type error: cannot read properties of null('addEventListner'). Can someone point me in the direction how to fix this

patent galeBOT
#

This post has been reserved for your question.

Hey @last ibex! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.