😺

Vanilla JavaScriptで要素に複数のCSSを設定する方法

2024/11/27に公開

よく見るstyle指定方法

element.style.color = "red";
element.style.fontSize = "20px";

Object.assign

Object.assign(element.style, {
    fontSize: "50px",
    color: "red",
    textAlign: "center",
});

setAttribute

element.setAttribute('style','color:red','font-size:14px');

CssText

element.style.cssText = `
    width: 80%;
    height: 400px;
    background-color: blue;
`;

Discussion