I am trying to remove the image from the following html, but am running into trouble. I am able to specify the ID is java script but am not sure how to remove the associated img.
<a href="https://google.com" target="_blank" id="my_banner_image" style="display: block;">
<img width="970" height="250" src="https://via.placeholder.com/970x250.png" boarder="0">
</a>
I have tried using, but am not quite sure how to specify the img.
var element = document.getElementById("my_banner_image");
element.parentNode.removeChild(image);
Locate img element using querySelector
method:
document.getElementById("my_banner_image")
.querySelector('img')
.remove()
It will remove the first img tag inside element with id my_banner_image
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.