I'm new to HTML, CSS, and Java programming.
I'm trying to change the color and text of an HTML element in JavaScript. Here is what I have. (Pressure_OK is tied to an input; you can manually set it to 0 or 1.) Basically, if the input is 0, then I want it to pass Okay in text form, but I want the text to be green. Otherwise, I want it to be Not Okay in red.
<p id="pressure"></p>
<script>
var Pressure;
if ('"Pressure_Ok"'==1)
{
Pressure ="Okay";
press = document.getElementById("pressure").innerHTML = Pressure;
press.style.color= 'green';
}
else
{
Pressure ="Gas Pressure: Not Okay";
press = document.getElementById("pressure").innerHTML = Pressure;
press.style.color= 'red';
}
</script>
'"Pressure_Ok"'is this your variable name which holds the value ?pressis not assigned the DOM object, but it's.innerHTML. You need tovar press = document.getElementById("pressure");and THEN on another line, assign thetextContent(if you're not assigning HTML, don't useinnerHTML. Then set the DOM color