PDA

Click to See Complete Forum and Search --> : Hiding an Image..


anoop007
Feb 25th, 2001, 06:41 AM
How to hide an image using script?

Psyrus
Feb 25th, 2001, 02:56 PM
You can wrap your image in a <DIV></DIV> and then set the <DIV>'s visibility property to hidden.

<script>

div1.visibility = 'hidden';

</script>

<div ID = "div1">
<img SRC = "/myimage.gif">
</div>

You can then display it again in script by setting the same property to 'visible'.

Feb 25th, 2001, 07:00 PM
thanks very much...

i didn't know the property was .visibility

i kept trying div1.visible=false..

Thanks a lot!

Feb 25th, 2001, 10:43 PM
but this isn't working :( either

Psyrus
Feb 26th, 2001, 10:59 AM
Add this style in the document head:

<style>

#div1 {visibility:hidden;}

</style>

Give the <DIV> and ID of div1

<div ID = "div1"><img SRC = "/myImage.gif"></div>

That should do it.

In order to access a style in script it must be defined in the document. Sorry, my mistake. To access this attribute from script to hide or show it you could then use this syntax:

div1.style.visibility = 'visible';
div1.style.visibility = 'hidden';

Feb 26th, 2001, 06:09 PM
oh yes i figured it out later.. thanks anyway..

I used div1.style.display = "none" .. this won't work in Netscape

Will your code work in Netscape?

Psyrus
Feb 26th, 2001, 10:55 PM
Netscape doesn't support the ".style" in code. There is a way to access it in Netscape but I'm not totally sure of the proper syntax and I don't have it installed to test it out, sorry.

Feb 27th, 2001, 02:43 AM
oh...

but i have an alternative for Netscape.