i wanted to create a webpage for creating memes as a fun project.
so far, i am attempting to add a new image element to the body of the document via JS using the url that is entered into the label with input type of url, but the image does not seem to load
//via the code below, i was expecting the actual image of the url to appear on the webpage after appending the image element to the dom but that does no seem to be the case
const form = document.querySelector('#form');
form.addEventListener('submit', function (e) {
e.preventDefault();
const newImage = document.createElement('img');
const newImageValue =
document.querySelector('#imageLink').value;
if (newImageValue === '') {
alert('Please enter a URL');
return;
}
newImage.src = newImageValue;
newImage.alt = 'Meme Image';
document.body.appendChild(newImage);
document.querySelector("imageLink").reset;
});
2
Answers
It looks like you are missing the
#
heredocument.querySelector("imageLink").reset
when selecting the code which causing the code to breakreset()
new FormData()
efficiently, does not need any query selector again.