คุณสมบัติ HTML DOM Style fontStyle ใช้สำหรับการตั้งค่าหรือส่งคืนรูปแบบตัวอักษรของข้อความ ใช้เพื่อระบุรูปแบบปกติ ตัวเอียง หรือเฉียงสำหรับข้อความขององค์ประกอบ
ต่อไปนี้เป็นไวยากรณ์สำหรับ −
การตั้งค่าคุณสมบัติ fontStyle -
object.style.fontStyle = "normal|italic|oblique|initial|inherit"
ให้เราดูตัวอย่างคุณสมบัติ fontStyle -
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
#demo2,#demo1 {
font-family: 'times new roman';
font-size: 25px;
}
</style>
<script>
function changeFontStyle() {
document.getElementById("demo1").style.fontStyle="italic";
document.getElementById("demo2").style.fontStyle="italic";
document.getElementById("Sample").innerHTML="The font style has been changed for the above paragraphs.";
}
</script>
</head>
<body>
<div id="demo1" >This is demo text 1</div>
<div id="demo2">This is demo text 2</div>
<p>Change the above divs font style by clicking the below button</p>
<button onclick="changeFontStyle()">Change fontStyle </button>
<p id="Sample"></p>
</body>
</html> ผลลัพธ์

เมื่อคลิกที่ “เปลี่ยน fontStyle ปุ่ม −
