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

Cách ẩn phần tử HTML với JavaScript


Dùng thuộc tính visibility trong JavaScript để ẩn phần tử. Bạn có thể chạy mã sau để học cách dùng visibility ẩn phần tử −

Ví dụ

<!DOCTYPE html> <html>    <body>       <p id = "pid">Văn bản demo</p>       <button type = "button" onclick = "displayHide()">Ẩn</button>       <button type = "button" onclick = "displayShow()">Hiện</button>             <script>          function displayHide() {             document.getElementById("pid").style.visibility = "hidden";          }          function displayShow() {             document.getElementById("pid").style.visibility = "visible";          }       </script>    </body> </html>