Add CSS attributes to element with JavaScript

Setting the style attribute like that, overwrites the attribute and removes previously set styles.

What you really should do is set the styles directly instead by changing the style property :

function checkNr(id) {
    var elem  = document.getElementById(id),
        value = elem.value;
    if (parseFloat(value) == NaN) {"2px solid red";"rgb(255, 125, 115)";
    } else {"none";"rgb(255, 255, 255)";

Leave a Comment