Changing font color in javascript



PHP Snippet 1:

$("#divCheckPasswordMatch").html("Passwords do not match!");

PHP Snippet 2:

$("#divCheckPasswordMatch").html("<span style='color:red'>Passwords do not match!</span>");

PHP Snippet 3:

if (password != confirmPassword){
        $("#divCheckPasswordMatch").html("<span style='color:red'>Passwords do not match!</span>");
 }   else {
        $("#divCheckPasswordMatch").html("Passwords match.");
}

PHP Snippet 4:

if (password != confirmPassword)
{
    $("#divCheckPasswordMatch").html("Passwords do not match!");
    $("#divCheckPasswordMatch").css('color', 'red');
} else {
    $("#divCheckPasswordMatch").html("Passwords match.");
    $("#divCheckPasswordMatch").css('color', 'green');
}

PHP Snippet 5:

thePasswordTextEle = document.createElement("span")

if (password != confirmPassword)
{
    thePasswordTextEle.classList.add("red-text")
    thePasswordTextEle.innerHTML = "Password ***"
} else {
    thePasswordTextEle.classList.add("green-text")
    thePasswordTextEle.innerHTML = "Password ***"
}
document.querySelector('#divCheckPasswordMatch').innerHTML = thePasswordTextEle.outerHTML