I'm trying to do some mouseover things with images. I thought that I had everything exactly as it should be but the page can't seem to access the images I'm asking it to.
The idea is that the page has three pictures. One of a happy baby, a dog, and a happy cat. When the cursor goes over each picture, it changes to a different picture, and back again once the cursor is moved away.
Here is my code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Image Rollover</title>
<script type="text/javascript">
var imageName = '';
if(document.images)
{
var dog_on = new Image();
dog_on.src = 'images/mean_dog.gif';
var dog_off = new Image();
dog_off.src = 'images/dog.gif';
var cat_on = new Image();
cat_on.src = 'images/angry_cat.gif';
var cat_off = new Image();
cat_off.src = 'images/happy_cat.gif';
var baby_off = new Image();
baby_off.src = 'images/happy_baby.gif';
var baby_on = new Image();
baby_on.src = 'images/angry_baby.gif';
};
function imageOn(imageName)
{
if(document.images)
{
(imageName == 'happy_baby') ? document.images[0].src = baby_off.src : '';
(imageName == 'dog') ? document.images[1].src = dog_off.src : '';
(imageName == 'happy_cat') ? document.images[2].src = cat_off.src : '';
};
};
function imageOff(imageName)
{
if(document.images)
{
(imageName == 'angry_baby') ? document.images[0].src = baby_on.src : '';
(imageName == 'mean_dog') ? document.images[1].src = dog_on.src : '';
(imageName == 'angry_cat') ? document.images[2].src = cat_on.src : '';
};
};
</script>
</head>
<body>
<h2>Emotional Babies, Dogs, and Cats</h2>
<h3>Image Rollover</h3>
<p><img src ="images/happy_baby.gif , images/angry_baby.gif" width = "400" height = "208";
alt = "Baby here" name="baby"
onMouseOver = "imageOn('angry_baby'); return true;"
onMouseOut = "imageOff('happy_baby'); return true;">
</p>
<p><img src ="images/dog.gif , images/mean_dog.gif" width = "400" height = "208";
alt = "Dog here" name="dog"
onMouseOver = "imageOn('mean_dog'); return true;"
onMouseOut = "imageOff('dog'); return true;">
</p>
<p><img src ="images/happy_cat.gif , images/angry_cat.gif" width = "400" height = "208";
alt = "Cat here" name="cat"
onMouseOver = "imageOn('angry_cat'); return true;"
onMouseOut = "imageOff('happy_cat'); return true;">
</p>
</body>
</html>
I have a folder named "images" with the image names in the code...but it isn't accessing them.
Any guidance would be greatly appreciated. I apologize if the indentations are funky. I have my tab settings set to 2 in notepad++ and it still sometimes gets off when I paste it somewhere.