Reputation: 90
I try to change the color of a javascript result depending it's positive or negative.
I made many tries but not found the solution. Below my last try:
Javascript:
var calc = (a + b) * c;
document.getElementById('result').innerHTML = calc;
(0 < calc) ? document.getElementById('result').style.Color='green':document.getElementById('result').style.Color='red';
Html:
Result: <output id="result"></output>
Any idea ? Thanks
Upvotes: -1
Views: 54
Reputation: 2137
This is better:
var [a,b,c] = [1,2,3]
var calc = (a + b) * c;
document.getElementById('result').innerHTML = calc;
document.getElementById('result').style.color= (0 < calc) ? 'green':'red'
Result: <output id="result"></output>
Upvotes: 3