const elem = document.getElementById("elemId");
const style = getDefaultComputedStyle(elem);Window: getDefaultComputedStyle() method / notebook
Window: getDefaultComputedStyle() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
<div id="elem-container">dummy</div>
<div id="output"></div>#elem-container {
position: absolute;
left: 100px;
top: 200px;
height: 100px;
}const elem = document.getElementById("elem-container");
const theCSSprop = getDefaultComputedStyle(elem).position;
document.getElementById("output").textContent = theCSSprop; // outputs "static"<h3>generated content</h3>h3::after {
content: " rocks!";
}const h3 = document.querySelector("h3");
const result = getDefaultComputedStyle(h3, "::after").content;
console.log("the generated content is: ", result); // returns 'none'