Having an event mouseover
, I would like that when you move the mouse over the image, the image changes depending on what the current image is, if not, it is not changed.
HTML
<body>
<img src="ikefeliz_2.png" id="imagen">
</body>
JS
var ikefeliz="ikefeliz_2.png";
var marthfeliz="marthfeliz_2.png";
var ikepeligro="ikepeligro_2.png";
var marthpeligro="marthpeligro_2.png";
window.addEventListener('load', iniciar, false);
function iniciar(){
var imagen=document.getElementById('imagen');
imagen.addEventListener('mouseover', peligro, false);
}
function peligro(){
var imagen=document.getElementById('imagen');
switch (imagen.src) {
case ikefeliz:
document.getElementById('imagen').src=ikepeligro;
break;
case marthfeliz:
document.getElementById('imagen').src=marthpeligro;
break;
}
}