Thuộc tính style.textDecorationColor trong HTML DOM trả về và cho phép thay đổi màu sắc của đường trang trí văn bản (text decoration) của một phần tử trong tài liệu HTML.
Cú pháp
Lấy giá trị textDecorationColor
object.style.textDecorationColor
Thay đổi textDecorationColor
object.style.textDecorationColor = "color"
Ví dụ
Ví dụ sử dụng thuộc tính style.textDecorationColor:
<!DOCTYPE html>
<html>
<head>
<style>
body { color: #000; background: lightblue; height: 100vh; }
p { margin: 1.5rem auto; text-decoration: line-through; }
.btn { background: #db133a; border: none; height: 2rem; border-radius: 2px; width: 40%; display: block; color: #fff; outline: none; cursor: pointer; }
</style>
</head>
<body>
<h1>Ví dụ thuộc tính style textDecorationColor DOM</h1>
<p>Đây là đoạn văn 1 với một số văn bản giả. Đây là đoạn văn 1 với một số văn bản giả.</p>
<button onclick="add()" class="btn">Thay đổi textDecorationColor</button>
<script>
function add() {
document.querySelector('p').style.textDecorationColor = "#db133a";
}
</script>
</body>
</html>
Kết quả
Nhấn nút Thay đổi textDecorationColor để thay đổi màu đường gạch ngang văn bản đoạn văn.