Get a background color for a document - Javascript CSS Style Property

Javascript examples for CSS Style Property:backgroundColor

Description

Get a background color for a document

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 ava  2  s .  c om*/
    console.log(document.body.style.backgroundColor);
}
</script>

</body>
</html>

Related Tutorials