“GetComputedStyle” Kode Jawaban

JS Computed Style

// window.getComputedStyle(<element>).<css-attribute>
// example :
window.getComputedStyle(document.getElementById("11")).width
Condemned Crab

GetComputedStyle

let box = document.querySelector('.box');
let style = getComputedStyle(box);

let borderTopWidth = parseInt(style.borderTopWidth) || 0;
let borderLeftWidth = parseInt(style.borderLeftWidth) || 0;
let borderBottomWidth = parseInt(style.borderBottomWidth) || 0;
let borderRightWidth = parseInt(style.borderRightWidth) || 0;
Code language: JavaScript (javascript)
Comfortable Cobra

GetComputedStyle

const htmlBody = document.getElementByTagName("body")[0];
const htmlStyles = window.getComputedStyle(htmlBody);

console.log(htmlStyles["background-color"]); // rgb(243, 242, 239)
console.log(htmlStyles["font-size"]); // 16px
Wissam

Jawaban yang mirip dengan “GetComputedStyle”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya