I'm trying to write a javascript program which show an hidden image.
Here's the html part :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title> Exercice 3 </title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<header>
</header>
<section>
<article>
<figure>
<img src="images/powsoundeffect.png" alt="image" />
<figcaption>
Image 1
</figcaption>
</figure>
<figure>
<img src="images/thwack_soundeffect.png" alt="image" />
<figcaption>
Image 2
</figcaption>
</figure>
<figure>
<img src="images/tophat.png" alt="image" />
<figcaption>
Image 3
</figcaption>
</figure>
<figure>
<img src="images/1311511622.png" alt="image" />
<figcaption>
Image 4
</figcaption>
</figure>
<ul>
<li>
<a href="#"> Image 1 </a>
</li>
<li>
<a href="#"> Image 2 </a>
</li>
<li>
<a href="#"> Image 2 </a>
</li>
<li>
<a href="#"> Image 2 </a>
</li>
</ul>
</article>
</section>
<script type="text/Javascript" src="script.js" >
</script>
</body>
</html>
The css :
figure {
width: 20%;
position: absolute;
visibility: hidden;
}
ul li {
border: 1px solid black;
width: 10%;
}
The script :
var arrayA = document.querySelectorAll('a');
var arrayImg = document.querySelectorAll('figure');
function show_Image(text, img) {
text.style.fontSize = '2em';
arrayImg[img].style.visibility = 'visible';
}
for (var i = 0, c = arrayA.length; i < c; i++) {
arrayA[i].addEventListener('mouseover', function(e) {
show_Image(e.target, i);
},
false);
}
When I try to run the script the following error occurs on safari :
TypeError: 'undefined' is not an object (evaluating 'arrayImg[img].style')
and on chromium :
Uncaught TypeError: Cannot read property 'style' of undefined
It seems that the arrayImg is not containing object with the querySelector and I don't see why ... Anyone can help me on this ?
Thanks !