Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to add css in innerText

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

document.getElementById('warning').style.backgroundColor="yellow";
document.getElementById('warning').style.color="red";
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading