What JavaScript will remove all image tags?
Remove all images All the Docker images on a system can be listed by adding -a to the docker images command. Once you're sure you want to delete them all, you can add the -q flag to pass the image ID to docker rmi : List: docker images -a.
Remove all Containers: To remove all containers from the docker-machine, we need to get the ids of all the containers. We can simply get the ids of the containers with the command docker ps -aq, then by using the docker rm command, we can remove all the containers in the docker-machine.
To clean this up, you can use the docker container prune command. By default, you are prompted to continue. To bypass the prompt, use the -f or --force flag. Other filtering expressions are available.
The previous answer will only remove every second image.
Remember NodeLists returned by getElementsByTagName or other DOM methods are ‘live’. That means when you remove image 0, images 1–n move down to 0–(n-1); this is a ‘destructive iteration’.
To avoid this, either make a static Array copy of the NodeList (as the jQuery answer is effectively doing), or, faster, just iterate the list backwards:
for (var i= document.images.length; i-->0;)
document.images[i].parentNode.removeChild(document.images[i]);
UPD: sorry, this is a wrong answer, see comments. This is a correct answer.
Something like this:
images = document.getElementsByTagName('img');
for (i = 0; i < images.length; i++) {
images[i].parentNode.removeChild(images[i]);
}
OR a slight modification of my first attempt to answer this question:
var images = document.getElementsByTagName('img');
var l = images.length;
for (var i = 0; i < l; i++) {
images[0].parentNode.removeChild(images[0]);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With