Page 1 sur 1

Bug ? Echange couleur back / text en js

Publié : 23 juin 2024, 06:42
par frg10

Bonjour,

J'essaie cela :

function colorInvert(elem)
{ if(typeof elem==="string") elem=document.getElementById(elem);
let computedStyle=window.getComputedStyle(elem);
let backgroundColor=computedStyle.backgroundColor;
let textColor=computedStyle.color;

Code : Tout sélectionner

elem.style.backgroundColor = textColor;
elem.style.color = backgroundColor;

}

NB : les couleurs sont héritées de l'élément parent (txt noir, couleur blanc).

Je me retrouve systématiquement avec un tex noir sur fond noir et ce n'est pas très lisible.