'How to resolve span color style not listening when manipulated from JavaScript Command

Okay guys, I am building a user registration form with bootstrap and some JavaScript. I have a problem styling a span element id from JavaScript. I have a button that fires a JavaScript event handler that needs to validate the input a user enters into a form. I told my JavaScript function to check the length of the first field and if user enters nothing then this span needs to have a color of red and display the message "Looks like we need this field", the message displays but the JavaScript styling does not work. Chrome's debug console displays the message signup.html:99 Uncaught TypeError: Cannot set properties of undefined (setting 'color') at validate (signup.html:99:55). Help me style my span element to be red from JavaScript(initially it is gray with the message Enter your full names in the field above).

<!DOCTYPE html>
<html>
<body>
<div class="form-group">
    <label for="exampleInputEmail1">Full Names</label>
    <input type="text" class="form-control" id="f_names" aria-describedby="emailHelp" placeholder="Full Names">
    <small id="nameHelp" class="form-text text-muted">Enter your full names separated by a space</small>
  </div>
 <button type="submit" class="btn btn-primary" onclick="validate()">Submit</button>
</body>
</html>
<script>
 function validate(){
    //define the data field values
    let f_names=document.getElementById("f_names").value;
     if(f_names.length==0){
     //find the span error tag and fill its inner data
     //this line below throws an error
     document.getElementById("nameHelp").Style.color="red";
     document.getElementById("nameHelp").innerText="Looks like we need this field";
   }
}
</script>

Why isn't element.style.color= working and how can I workaround this?



Solution 1:[1]

style property of the element must be lowercase

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jgondev