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

ออบเจ็กต์ HTML DOM Section

ออบเจ็กต์ HTML DOM Section แทนองค์ประกอบ <section> ในเอกสาร HTML

ลองสร้าง section object

รูปแบบไวยากรณ์ (Syntax)

document.createElement(“SECTION”);

ตัวอย่าง

ตัวอย่างการใช้งานออบเจ็กต์ HTML DOM Section:

<!DOCTYPE html> <html> <head> <style>    body{       text-align:center;       background-color:#fff;       color:#0197F6;    }    h1{       color:#23CE6B;    }    .drop-down{       width:35%;       border:2px solid #fff;       font-weight:bold;       padding:8px;    }    .btn{       background-color:#fff;       border:1.5px dashed #0197F6;       height:2rem;       border-radius:2px;       width:60%;       margin:2rem auto;       display:block;       color:#0197F6;       outline:none;       cursor:pointer;    } </style> </head> <body> <h1>ตัวอย่าง DOM Section Object</h1> <button onclick="createSection()" class="btn">สร้าง section object</button> <script>    function createSection() {       var sectionElement = document.createElement("SECTION");       sectionElement.innerHTML="

      Hi! I'm a <section> element in HTML";

      document.body.appendChild(sectionElement);

   } </script> </body> </html>

ผลลัพธ์

โค้ดด้านบนจะให้ผลลัพธ์ดังนี้:

ออบเจ็กต์ HTML DOM Section


ออบเจ็กต์ HTML DOM Section