Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Đối tượng Section trong HTML DOM

Đối tượng Section trong HTML DOM đại diện cho phần tử <section> của một tài liệu HTML.

Hãy tạo đối tượng section:

Cú pháp

Cú pháp như sau:

document.createElement(“SECTION”);

Ví dụ

Dưới đây là ví dụ về đối tượng 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>Demo đối tượng DOM Section</h1> <button onclick="createSection()" class="btn">Tạo một đối tượng section</button> <script>    function createSection() {       var sectionElement = document.createElement("SECTION");       sectionElement.innerHTML="<p>       Xin chào! Tôi là một phần tử <section> trong HTML";</p>       document.body.appendChild(sectionElement);    } </script> </body> </html>

Kết quả

Đoạn mã trên sẽ cho kết quả như sau:

Đối tượng Section trong HTML DOM


Đối tượng Section trong HTML DOM