How to set whether an element should be visible in JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

Use the visibility property in JavaScript to hide or show an element.


You can try to run the following code to learn how to work with visibility property −

<!DOCTYPE html>
      <p id = "pid">Demo Text</p>
      <button type = "button" onclick = "displayHide()"> Hide </button>
      <button type = "button" onclick = "displayShow()"> Show </button>
         function displayHide() {
            document.getElementById("pid").style.visibility = "hidden";

         function displayShow() {
            document.getElementById("pid").style.visibility = "visible";
Updated on 23-Jun-2020 11:39:39