<!DOCTYPE html>
<html lang="en-US">
<body style="font-weight:bold">
<div style="border-top: 1px solid blue; color:red" id="elt">
An example div
</div>
<pre id="out"></pre>
<script !src="">
const element = document.getElementById("elt");
const out = document.getElementById("out");
const elementStyle = element.style;
// We loop through all styles (for…of doesn't work with CSStyleDeclaration)
for (const prop in elementStyle) {
if (Object.hasOwn(elementStyle, prop)) {
out.textContent += `${
elementStyle[prop]
} = '${elementStyle.getPropertyValue(elementStyle[prop])}'\n`;
}
}
</script>
</body>
</html>
댓글 영역