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

How do I hide a picture when loading a page?

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
> 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.
Jul 20 '05 #2

P: n/a
"KC Wong" <ev**********@yahoo.com.hk> writes:
I want to load a page. I want to have a picture that remains
hidden until a mouseover action takes place.
<script> Remember the required attribute "type"
<script type="text/javascript">
<!--
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

P: n/a
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
Jul 20 '05 #4

P: n/a
"KC Wong" <ev**********@yahoo.com.hk> writes:
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).
<!--

You don't need HTML comments in Javascript


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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.