Using javascript, I am adding two buttons, one will add a picture and the other will delete a picture. I'm just practicing for an exam...
The button and function to add the picture work beautifully, I am struggling with the function to delete the picture. If I add the two buttons, and the picture to the website, and add an id to the picture, and delete that picture through the ID. But if I only the two buttons and try to start adding pictures, then I would have no ID, so I am lost!
The deleteMe function below works fine deleting that first picture. But I don't want to have any pictures when I load the website, I only want to have the two buttons to add and remove. So I don't know how to remove the elements. Here is what I have so far for the two functions, thanks!!!:
function deleteMe(){
var toDelete = document.getElementById('image23');
toDelete.parentNode.removeChild(toDelete);
}
function addMe(){
var img = document.createElement('IMG');
img.setAttribute("src", "elephant.jpg");
img.setAttribute("width", "60");
img.setAttribute("height", "60");
document.body.appendChild(img);
}