hello I have a function in javascript that generates an error message
But I would like to add css in the error message
for example a yellow background and a red color
//ciblage
let btn = document.getElementsByClassName("buttons");
let D = document.getElementsByClassName("div_text");
let errorMessage = document.createElement("div");
stringLength = document.getElementById('username');
const regex = /\W/;
errorMessage.id = 'warning';
D[0].appendChild(errorMessage);
stringLength.addEventListener('input', function (evt) {
if (stringLength.value.length > 10) {
document.getElementById('warning').innerText = "le nombre de caractères maximum autorisés est de 10"
btn[0].disabled = true;
}
});
>Solution :
document.getElementById('warning').style.backgroundColor="yellow";
document.getElementById('warning').style.color="red";