Thiết lập giá trị thuộc tính đối tượng style trong JavaScript

Thiết lập giá trị thuộc tính đối tượng style trong JavaScript

Thiết lập giá trị thuộc tính đối tượng style trong JavaScript

Tự code rồi chạy thử... Chạy Thử
<!DOCTYPE html>
<html>
<head>
<title>Thiết lập giá trị thuộc tính đối tượng style trong JavaScript</title>
</head>
<body>

<h1>Thiết lập giá trị thuộc tính đối tượng style trong JavaScript</h1>
<p>Dùng để css cho một phần tử HTML bằng cách khởi tạo thuộc tính và gán giá trị cho thuộc tính đó:</p>

<div id="divid">Thẻ DIV cần CSS</div>
<p>Click vào nút THÊM CSS để css cho phần tử HTML</p>
<button onclick="themCss()">THÊM CSS</button>
<script>
function themCss() {
  document.getElementById("divid").style.backgroundColor = "black";
  document.getElementById("divid").style.color = "#fff";
  document.getElementById("divid").style.textAlign = "center";
  document.getElementById("divid").style.lineHeight = "50px";
  document.getElementById("divid").style.border = "3px solid red";
  document.getElementById("divid").style.fontWeight = "bold";
  document.getElementById("divid").style.fontSize = "20px";
  document.getElementById("divid").style.textTransform = "uppercase";
}
</script>
</body>
</html>
Thiết lập giá trị thuộc tính đối tượng style trong JavaScript nằm trong bài viết Đối tượng style trong JavaScript