This is done by assigning none value to style.display. We are hiding the div element by applying the style.display property, and hiding the element by applying the style.visibility property. As the user clicks on the button, the function is called to hide the element. Here, there is a div element and heading element on which we are applying the properties. In this example, we are using both style.display and style.visibility JavaScript properties to see the difference between both of them. comes from reusing and adapting a script but not testing as I write. The visibility property in JavaScript is also used to hide. hide) an element until a function/promise is complete, then hide (or show) that element after the function/promise is complete. For these functions to work, it's required to store the initial/default display style of an element. JsFiddle is the coolest thing I have seen in a long time If you use toggle () instead of fadeIn () you can show/hide the answers rather than just showing them. In JavaScript, we can hide the elements using the style.display or by using the style.visibility. On clicking the button, the output will be - Example3 The following helpers are basically vanilla JavaScript clones of jQuery's. Example of the JavaScript's style.visibility propertyĭocument.getElementById("div").style.visibility = "hidden" ĭocument.getElementById("p").style.visibility = "hidden" Īfter the execution of the above code, the output is - In this new toggleClock() function, your are using JavaScript to retrieve the clock element, get the current value of its display style, then checking it.