Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h1>The Window Object</h1>
<h2 id="test" style="background-color:lightblue">The getComputedStyle() Method</h2>
<p>The computed background color for the test div is:</p>
<p id="demo"></p>
<script>
const element = document.getElementById("test");
const cssObj = window.getComputedStyle(element, null);
let bgColor = cssObj.getPropertyValue("background-color");
document.getElementById("demo").innerHTML = bgColor;
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_getcomputedstyle by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 21 Dec 2022 17:39:27 GMT -->
</html>