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

วิธีตั้งค่า Display Type ขององค์ประกอบด้วย JavaScript

ใช้คุณสมบัติ display เพื่อเปลี่ยนประเภทการแสดงผลขององค์ประกอบ เช่น block, inline, flex, grid, none (ซ่อน)

ตัวอย่าง

<!DOCTYPE html>
<html>
  <head>
    <style>
      #myID {
        width: 250px;
        height: 200px;
        background-color: green;
      }
    </style>
  </head>
  <body>
    <button onclick="display()">Set display as none</button>
    <div id="myID">
      <h1>Heading Level 1 for Demo</h1>
      This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text.
    </div>
    <script>
      function display() {
        document.getElementById("myID").style.display = "none";
      }
    </script>
  </body>
</html>