tags:

views:

639

answers:

6
+1  Q: 

IMG without src

My JS code includes some images that are empty at the beginning (without src attribute specified at all + display:none).

When added to sites with CSS1 compatibility I see broken image icon where the image should be even though the images are supposed not to be displayed (display:none).

Any idea how I can hide the broken image icons?

Notes: I don't want to load empty images. I tried width and height= 1px or 0px . didn't work. specifying src="" also gives empty image icons.

Edit: I found the solution: add style="display:none" to the img definition (Not in CSS)

+4  A: 

Have you tried wrapping the images inside a div and hiding the div instead?

tehvan
+2  A: 

how about just having a placeholder div tag and replacing it with an image when the time comes to show the image? any decent ajax framework (e.g. jQuery) will make this easy to do so it works across all major browsers

AndreasKnudsen
A: 

If you are using a JavaScript library it may be worth applying a class to name to all of these images and letting the library handle it. Prototype example using a class name of myImages would be

var images = $$('.myImages');

if (image != null)
{
    for (int i = 0; i < images.Length; i++)
    {
        images[i].hide;
    }
}

You would still need to add the style attribute style="display: none;" to the images

Nick Allen - Tungle139
Thanks for the answer. I'm not using a library.
Nir
+1  A: 

in addition to display:none, maybe try setting visibility:hidden

ob
+1  A: 

My JS code includes some images that are empty at the beginning (without src attribute specified

That's not a valid state for an image. Best use a placeholder transparent image or leave the image out of the DOM until you can set a ‘real’ src attribute.

I see broken image icon where the image should be even though the images are supposed not to be displayed (display:none).

Doesn't happen for me, either ‘display: none’ or ‘visibility: hidden’ removes the visible image from the page. Example code demonstrating the problem, and which browser(s)?

bobince
The reason for the differences is that the site its attached to is in CSS1 compatibilty mode.
Nir
If you are talking about document.compatMode='CSS1Compat', that's perfectly normal Standards Mode. But the behaviour you allege should not and does not happen for me, neither in Standards nor Quirks modes. I think something different is happening, but we're not going to find out without code.
bobince
A: 

The solution is quite simple:

add style="display:none" to the img definition (Not in CSS)

Nir