상세 컨텐츠

본문 제목

[자바스크립트] hasown 이 객체가 [이름]의 속성을 가지고있느 안가지고있나

카테고리 없음

by esoesmio 2023. 5. 18. 20:23

본문

<!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>

댓글 영역