My code for replacing my icon image on mouseover and mouseout isn't working. I'm trying to change each icon every time I mouseover and change it back to original on mouseout. I can't seem to find the problem and I would also like to know if there is any way to simplify my code. Thank you!
Assuming that all the id and image sources are correct! Image
window.addEventListener('load', function(){
var oImg1 = document.getElementById("image1").src = "images/fleche1.gif";
var oImg2 = document.getElementById("image2").src = "images/fleche1.gif";
var oImg3 = document.getElementById("image3").src = "images/fleche1.gif";
var oImg4 = document.getElementById("image4").src = "images/fleche1.gif";
var oImg5 = document.getElementById("image5").src = "images/fleche1.gif";
var oImg6 = document.getElementById("image6").src = "images/fleche1.gif";
var oImg7 = document.getElementById("image7").src = "images/fleche1.gif";
var oImg8 = document.getElementById("image8").src = "images/fleche1.gif";
var oImg9 = document.getElementById("image9").src = "images/fleche1.gif";
// Fonction Fleche2
oImg1.addEventListener("mouseover", function(){
this.src="images/fleche2.gif";
});
// Fonction Fleche1
oImg1.addEventListener("mouseout", function() {
this.src = "images/fleche1.gif";
// Fonction Fleche2
oImg2.addEventListener("mouseover", function(){
this.src="images/fleche2.gif";
});
// Fonction Fleche1
oImg2.addEventListener("mouseout", function() {
this.src = "images/fleche1.gif";
// Fonction Fleche2
oImg3.addEventListener("mouseover", function(){
this.src="images/fleche2.gif";
});
// Fonction Fleche1
oImg3.addEventListener("mouseout", function() {
this.src = "images/fleche1.gif";
// Fonction Fleche2
oImg4.addEventListener("mouseover", function(){
this.src="images/fleche2.gif";
});
// Fonction Fleche1
oImg4.addEventListener("mouseout", function() {
this.src = "images/fleche1.gif";
// Fonction Fleche2
oImg5.addEventListener("mouseover", function(){
this.src="images/fleche2.gif";
});
// Fonction Fleche1
oImg5.addEventListener("mouseout", function() {
this.src = "images/fleche1.gif";
// Fonction Fleche2
oImg6.addEventListener("mouseover", function(){
this.src="images/fleche2.gif";
});
// Fonction Fleche1
oImg6.addEventListener("mouseout", function() {
this.src = "images/fleche1.gif";
// Fonction Fleche2
oImg7.addEventListener("mouseover", function(){
this.src="images/fleche2.gif";
});
// Fonction Fleche1
oImg7.addEventListener("mouseout", function() {
this.src = "images/fleche1.gif";
// Fonction Fleche2
oImg8.addEventListener("mouseover", function(){
this.src="images/fleche2.gif";
});
// Fonction Fleche1
oImg8.addEventListener("mouseout", function() {
this.src = "images/fleche1.gif";
// Fonction Fleche2
oImg9.addEventListener("mouseover", function(){
this.src="images/fleche2.gif";
});
// Fonction Fleche1
oImg9.addEventListener("mouseout", function() {
this.src = "images/fleche1.gif";
});