Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> HTML

ออบเจ็กต์ HR ของ HTML DOM

ออบเจ็กต์ HR ของ HTML DOM แทนองค์ประกอบ <hr> ของเอกสาร HTML

สร้างออบเจ็กต์ hr −

ไวยากรณ์

ไวยากรณ์มีดังนี้ −

document.createElement("HR");

ลองดูตัวอย่างออบเจ็กต์ hr −

ตัวอย่าง

<!DOCTYPE html> <html> <style>    body {       text-align: center;       background-color: #fff;       color: #0197F6;    }    h1 {       color: #23CE6B;    }    .btn {       background-color: #fff;       border: 2px solid #0197F6;       height: 2rem;       width: 40%;       margin: 2rem auto;       display: block;       color: #0197F6;       outline: none;       cursor: pointer;       border-radius: 20px;    }    hr {       border-color: #db133a;    } </style> <body> <h1>การสาธิตออบเจ็กต์ hr ของ DOM</h1> <button onclick="createHr()" class="btn">สร้างออบเจ็กต์ hr</button> <script>    function createHr() {       var insElement = document.createElement("HR");       document.body.appendChild(insElement);    } </script> </body> </html>

ผลลัพธ์

คลิกปุ่ม สร้างออบเจ็กต์ hr เพื่อสร้างออบเจ็กต์ hr −

ออบเจ็กต์ HR ของ HTML DOM

ออบเจ็กต์ HR ของ HTML DOM