How do I hide a picture when loading a page?

O

OM

I want to load a page.
I want to have a picture that remains hidden until a mouseover action takes
place.

How do I do this?
I'm not sure. : (

Any help would be appreciated.

Thanks.

OM
 
K

KC Wong

I want to load a page.
I want to have a picture that remains hidden until a mouseover action takes
place.

How do I do this?
I'm not sure. : (

Something like this:

<html>
<head>
<title>Hiding things until mouseover</title>
<script>
<!--
function toggle(show) {
if (show) {
document.myImage.style.visibility = "visible";
} else {
document.myImage.style.visibility = "hidden";
}
return false;
}
//-->
</script>
</head>
<body onload="debug()">
<div onmouseover="toggle(true);" onmouseout="toggle(false);">Show
Image</div>
<img name="myImage" src="img.jpg" style="{visibility: hidden;}" />
</body>
</html>

You need to refer to the documentation more often... go to
http://www.w3c.org/
and click menu item HTML and CSS.
 
L

Lasse Reichstein Nielsen

Remember the required attribute "type"

You don't need HTML comments in Javascript
function toggle(show) {
if (show) {
document.myImage.style.visibility = "visible";

This is not very protable. Not all browsers make named elements
properties of the document element. You can, portably, use
document.images['myImage'].style.visibility =
(show?"visible":"hidden");
<body onload="debug()">

This is to trigger the Netscape or Mozilla debugger, right? I don't
even think you need to call it, just writing "debug" should be enough.

/L
 
K

KC Wong

Thanks, Lasse... I haven't coded any JavaScript for years, but recently
picked it up again because I have to integrate 2 web sites. Seems I've
forgotten most of the good practices :(

- Remember the required attribute "type", <script type="text/javascript">
- document.images['myImage']

I'm off to tidy up my code before they're deployed...
You don't need HTML comments in Javascript
document.images['myImage'].style.visibility =
(show?"visible":"hidden");

That's one habit I learned from a book many years ago... so that if the
browser does not support JavaScript, your code won't show up on the page.


KC
 
L

Lasse Reichstein Nielsen

KC Wong said:
Thanks, Lasse... I haven't coded any JavaScript for years, but recently
picked it up again because I have to integrate 2 web sites. Seems I've
forgotten most of the good practices :(

Years ago, there were two browsers and almost no standards, so good
practices were often anything that worked. While IE still has a huge
market share, there are other browsers out there. Each is probably
counted only in singe digit percentages, I bet they will grow as more
people start using alternative platforms, e.g., mobile phones with
browsers (where Opera is currently popular with phone makers).
That's one habit I learned from a book many years ago... so that if the
browser does not support JavaScript, your code won't show up on the page.

Almost correct. If the browser don't understand the script *tag*, it
will show the contents, and you need to hide it with HTML comments. If
it understands the script tag, i.e., understands HTML 3.2, then it
doesn't matter if it can execute the script or not, it still won't
show the contents.

HTML 3.2 was made a recommendation in January 1997, and any serious
browser made after that (and most of the ones made while HTML 3.2 was
in development) will not need the script to be hidden. I think it is
safe to say that no browser in current use needs the HTML comments.

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top