Bonsoir,
j'ai un problème avec la fonction setAttribute() :

voilà ma fonction :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
//Fonction qui modifie l'image en fonction d'une autre
function change_image(){
    var fond = document.getElementById('monId');
    if (fond.style.backgroundImage == url(mon_image1.jpg)){  
        fond.setAttribute('style','background-image:url(mon_image2.jpg)');
    } else {
        fond.setAttribute('style','mon_image1');
    }
}
Cette fonction marche correctement sous FireFox mais pas sous Internet Explorer.
Après quelques recherches j'ai vu qu'il fallait mieux procéder ainsi pour Internet Explorer :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
//Fonction qui modifie l'image en fonction d'une autre
function change_image(){
    var fond = document.getElementById('monId');
    if (fond.style.backgroundImage == url(mon_image1.jpg)){  
        fond.style.setAttribute( 'cssText','background-image:url(mon_image1.jpg);');
    } else {
        fond.style.setAttribute( 'cssText','background-image:url(mon_image2.jpg);');
    }
}
Cette fois ma fonction réagit mais place ma nouvelle image en haut de page indifféremment de l'objet référencé par 'monID'.

Quel peut être le problème ?
Merci !