I'm writing some very simple code to dynamically change image src on mouseover/mouseout:
function e(id) {
return document.getElementById(id);
}
function changeimg_bw(ele) {
e(ele).src='rating_bw.png';
}
function changeimg_color(ele)
e(ele).src='rating_color.png';
}
for(var i=1;i<=5;i++) {
var img ='rating'+i;
e(img).addEventListener('mouseover', function(event) {
changeimg_color(img);
});
e(img).addEventListener('mouseout', function(event) {
changeimg_bw(img);
});
}
The idea is fairly simple: use an array of images to simulate the rating bar. And when some image is covered by mouse pointer, it should change color (well ideally including all previous images should change color but I got stuck before getting there). My question is when I hover on any image, only the last image changes color ('rating5'). Looks when i == 5 its eventlistener overwrote all other eventlistener (i=1,2,3,4)?