Javascript DOM CSS Style backgroundColor Property set

Introduction

Set a background color for a document:

document.body.style.backgroundColor = "red";

View in separate window

<!DOCTYPE html>
<html>
<body>

<h1>Hello World!</h1>

<button type="button" onclick="myFunction()">Set background color</button>

<script>
function myFunction() {//w w w  .j a v  a  2  s.  c  om
  document.body.style.backgroundColor = "red";
}
</script>

</body>
</html>



PreviousNext

Related