Passage de querySelector à querySelectorAll
Bonjour,
J'ai un script qui fonctionne pour une image.
Code:
1 2 3 4 5 6 7 8 9 10
| const imax = document.querySelector ('img.picture');
const tist = imax.alt;
const idImg = imax.id.split ('X');
const ca_id = idImg[0];
const height = idImg[1];
const img_format = idImg[2];
imax.addEventListener ('click', function() {PopGrand (ca_id, tist, height, img_format)}); |
À présent il y a plusieurs images, j'ai transformé le script comme suit.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| const imax = document.querySelectorAll ('img.picture');
for (let i = 0; i < imax.length; i++)
{
const tist = imax[i].alt;
const idImg = imax[i].id.split ('X');
const ca_id = idImg[0];
const height = idImg[1];
const img_format = idImg[2];
imax[i].addEventListener ('click', function() {PopGrand (ca_id, tist, height, img_format)});
} |
Le script fonctionne mais bizarrement il plante tous les autres scripts plus bas dans la page.
Voyez-vous l'erreur ?
Merci d'avance.