Javascript DOM HTML Body get background color

Introduction

Return the background color of a document:

alert(document.body.style.backgroundColor);

View in separate window

<!DOCTYPE html>
<html>
<body style="background-color:yellow;">

<h1>Hello World!</h1>

<button type="button" onclick="myFunction()">Get background color</button>
<p id="demo"></p>
<script>
function myFunction() {//from  w  ww  .  jav  a 2 s .  c o  m
  document.getElementById("demo").innerHTML = document.body.style.backgroundColor;
}
</script>

</body>
</html>



PreviousNext

Related