1

So. First I used this <img onmouseover="preview.src=img1.src" id="img1" src="pic01.jpg" alt="Image Not Loaded"/> but it didn't work. I changed 'id' to 'name' and it worked. But name attribute is obsolete and not recommended to use. So what should I use? I'm trying to make a image gallery for my school project. And because it's a school project it must be "perfect" html. No any errors.

And btw. 'id' worked in Internet Explorer and Mozilla Firefox. But not in Google Chrome.

My whole code is this:

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>

<div class="thumbnails">
    <img onmouseover="preview.src=img1.src" name="img1" src="image001.jpg" alt="Image Not Loaded"/>
    <img onmouseover="preview.src=img2.src" name="img2" src="image002.jpg" alt="Image Not Loaded"/>
</div>
<br>

<div class="preview" style="text-align: center;">

    <img name="preview" src="image001.jpg" alt="No Image Loaded"/>

</div>

</body>

</html>

And this works in Google Chrome when I change id to name.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118

1 Answers1

0

Likely the variables preview and/or img1 are undefined. I assume you're trying:

<img onmouseover="document.getElementById('preview').src=document.getElementById('img1').src" id="img1" src="pic01.jpg" alt="Image Not Loaded"/>
Jonathan
  • 8,771
  • 4
  • 41
  • 78
  • And I solved the problem! I moved css style from style.css to HTML-document. Now it works fine. And thank you for your help! – user3343295 Feb 23 '14 at 15:11
  • @user3343295 Your way of doing it is very unreliable, you should use `document.getElementById`. See the [answer to this question](http://stackoverflow.com/questions/21971685/element-with-name-or-id-usable-by-default) (and the linked question) for details. – Jonathan Feb 23 '14 at 17:43