Javascript DOM CSS Style backgroundColor Property get for document

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  w w .java2  s.  c  om*/
  document.getElementById("demo").innerHTML = document.body.style.backgroundColor;
}
</script>

</body>
</html>



PreviousNext

Related