1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| const
tbody = document.querySelector( "#tbody" );
function setIndex( index ){
return ( ++index > 2 ? 0: index );
}
tbody.addEventListener( "click", ev => {
// debug, console touche F12
//console.log( "ev.currentTarget = ", ev.currentTarget, "ev.target = ", ev.target, "ev.target.nodeName = ", ev.target.nodeName );
if ( ev.target.nodeName === "IMG" ){
let
src = ev.target.src,
ext = ".gif",
pos = src.lastIndexOf( ext ),
index = setIndex( src.substr( --pos, 1 ) ),
newSrc = dirImg + index + ext; // dirImg est défini dans le code php
//console.log( "src = ", src, "pos = ", pos, "index = ", index );
ev.target.src = newSrc;
}
}, false); |
Partager