Get the background color of a document via body background property - Javascript CSS Style Property

Javascript examples for CSS Style Property:backgroundColor

Description

Get the background color of a document via body background property

Demo Code

ResultView the demo in separate window

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

<h1>Hello World!</h1>

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

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

</body>
</html>

Related Tutorials