By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,462 Members | 1,126 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,462 IT Pros & Developers. It's quick & easy.

problem hiding all image files in a html file

P: 2
Here is my source code which completely works:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <body>
  3.     <div id="div1">div1</div>
  4.     <div id="div2">div2</div>
  5.     <a href=# onclick=check()>delete all div</a>
  6.  
  7.     <script>
  8.      function check(){
  9.         x = document.getElementsByTagName("div");
  10.  
  11.         while(x.length>0){
  12.           document.getElementsByTagName("body")[0].removeChild(x[0]);
  13.     }
  14.      }
  15.     </script>
  16.   </body>
  17. </html>

However, this code will not work:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <body>
  3.     <img id="img1" src='image1.jpg'>
  4.     <img id="img2" src='image2.jpg'>
  5.     <a href=# onclick=check()>delete all img</a>
  6.  
  7.     <script>
  8.      function check(){
  9.         x = document.getElementsByTagName("img");
  10.  
  11.         while(x.length>0){
  12.           document.getElementsByTagName("body")[0].removeChild(x[0]);
  13.     }
  14.      }
  15.     </script>
  16.   </body>
  17. </html>
I want to hide all images of my webpage.
Any help appreciated.
Jan 5 '10 #1

✓ answered by Dormilich

I do apologize for any inconvenience I might have caused.
what inconvenience?
however, this code will not remove advertisement images.
maybe they are flash objects?
P.S. When you copy and paste, […] please remove that space when you paste it in location bar
if you wrap that in [code] … [/code], that doesn’t happen.

Share this Question
Share on Google+
3 Replies


Dormilich
Expert Mod 5K+
P: 8,639
However, this code will not work:
well, it works for me (FF 3.5/Mac)
Jan 5 '10 #2

P: 2
Dormilich,
I do apologize for any inconvenience I might have caused.

Actually, this is what I am trying to do:
Here is my code,

Expand|Select|Wrap|Line Numbers
  1. javascript:void(x=document.getElementsByTagName("img"));for(i=0;i<x.length;i++){void(x[i].style.display="none")}
you can type this in the browser's location bar,

What I wanted to do is to hide all the unnecessary images (the advertisements image) on the page,

The code works perfect on google images pages and some images pages, however, this code will not remove advertisement images.

Any help is appreciated.

P.S. When you copy and paste, you will get an unnecessary space character in the line getElementById("img"), please remove that space when you paste it in location bar
Jan 5 '10 #3

Dormilich
Expert Mod 5K+
P: 8,639
I do apologize for any inconvenience I might have caused.
what inconvenience?
however, this code will not remove advertisement images.
maybe they are flash objects?
P.S. When you copy and paste, […] please remove that space when you paste it in location bar
if you wrap that in [code] … [/code], that doesn’t happen.
Jan 5 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.