Computer >> 컴퓨터 >  >> 프로그램 작성 >> JavaScript

JavaScript로 요소의 표시 유형을 설정하는 방법은 무엇입니까?


요소의 표시 유형을 설정하려면 표시 특성. 요소를 숨기려면 없음을 사용하십시오.

예시

다음 코드를 실행하여 JavaScript로 요소의 표시 유형을 설정할 수 있습니다 −

<!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>