How to hide HTML element with JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

Use the visibility property in JavaScript to hide an element. You can try to run the following code to learn how to work with visibility property to hide an element −

Example

<!DOCTYPE html>
<html>
   <body>
      <p id = "pid">Demo Text</p>

      <button type = "button" onclick = "displayHide()">Hide</button>
      <button type = "button" onclick = "displayShow()">Show</button>
     
      <script>
         function displayHide() {
            document.getElementById("pid").style.visibility = "hidden";
         }
         function displayShow() {
            document.getElementById("pid").style.visibility = "visible";
         }
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 15:18:34
Advertisements