We would like to know how to change div background colour based on a value.
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function(){<!-- www . j ava 2 s. c o m-->
var actualchoices = 1
var scorecolor;
if (actualchoices >= 1) {
scorecolour = document.getElementById("main");
scorecolour.style.backgroundColor = "green"
} else {
scorecolour = document.getElementById("main");
scorecolour.style.backgroundColor = "red"
}
}
</script>
</head>
<body>
<div id="main">test</div>
</body>
</html>
The code above is rendered as follows: