Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide all images using javascript?

I'm injecting JavaScript code into a website for personal use, using a Google Chrome extension... I'd like to hide all images before the page loads... I've got the script to run before anything loads, but can't seem to get the correct code to hide the array of images... something like:

function beforeload(){
  document.getElementsByTagName('img')[0].style.display = "none"
}

Basically i want all the image tags to have style="display:none" added to the attributes. how do i do this?

like image 266
David Avatar asked Apr 25 '11 17:04

David


1 Answers

You need to loop on them

var images = document.getElementsByTagName('img');
for (i = 0; i < images.length;i++ ) {
    images[i].style.display = "none";
}
like image 188
Amr Elgarhy Avatar answered Sep 27 '22 21:09

Amr Elgarhy