JavaScript hide elements2 Apr 2025 | 3 min read In JavaScript, we can hide the elements using the style.display or by using the style.visibility. The visibility property in JavaScript is also used to hide an element. The difference between the style.display and style.visibility is when using visibility: hidden, the tag is not visible, but space is allocated. Using display: none, the tag is also not visible, but there is no space allocated on the page. In HTML, we can use the hidden attribute to hide the specified element. When the hidden attribute in HTML sets to true, the element is hidden, or when the value is false, the element is visible. SyntaxThe general syntax to hide an element using style.hidden and style.visibility is given as follows. Using style.hidden Using style.visibility Now, let's see some examples to understand the hiding of elements in javascript. Example1In this example, we will see how to remove elements by using JavaScript's style.display property. Here, there is a div element and a paragraph element that gets hide on clicking the given HTML button. We have to click the 'Click me!' button to see the effect. Output After the execution, the output will be - ![]() On clicking the button, the output will be - ![]() Example2In this example, we will see how to hide elements by using JavaScript's style.visibliity property. Here, a div element and a paragraph element get hidden, but their space is still allocated. We have to click the 'Click me!' button to see the effect. Output After the execution of the above code, the output is - ![]() On clicking the button, the output will be - ![]() Example3In this example, we are using both style.display and style.visibility JavaScript properties to see the difference between both of them. Here, there is a div element and <h3> heading element on which we are applying the properties. We are hiding the div element by applying the style.display property, and hiding the <h3> element by applying the style.visibility property. We have to click the 'Click me!' button to see the effect. Output In the output, we can see that the div element (on which we have applied style.visibility property) is hiding but still allocating the space. But the heading (on which we have applied style.display property) is hiding and not allocating any space. ![]() After clicking the button, the result will be - ![]() Next TopicMemoization-in-javascript |
Introduction: JavaScript has hardened its position as the go-to language for web development, fuelling dynamic and intuitive substance on the internet. To outfit its maximum capacity, developers depend on effective JavaScript editors. These editors act as vital buddies, offering features that upgrade efficiency, code quality, and...
5 min read
The jQuery JavaScript library offers jQuery DataTable, an intelligent and powerful plugin for upgrading HTML tables. It is an extremely adaptable application designed to improve data accessibility in HTML tables by displaying information in tables and adding interactions. jQuery DataTables makes it easy to add sophisticated functionality...
13 min read
? In JavaScript, an array is an effective way to store a collection of items. One of the basic things that we can do with an array is looping or iterating over each of the elements there. Let's see different ways how we can loop through an...
6 min read
An inline function with a name, also known as an anonymous function and assigned to a variable in JavaScript. JavaScript does not provide support for the traditional concept of inline functions as C or C++. Accordingly, there is no distinction between inline and anonymous functions. They are...
3 min read
React is a library created by Facebook which is now called Meta for its own platform but due to its popularity and advantages for creating user interfaces in web applications, it was made open source. React is most popular for creating single-page web applications which implies...
14 min read
The visibility property in JavaScript Style lets users show or hide an element. This element's visibility on the webpage is defined by its visibility property. Similar to visibility, another JavaScript property called hidden can be used to hide an element without removing the space it currently...
6 min read
Javascript regex groups [a|b] work for alternative numbers or characters available as a character in the string. We can use the numbers or any character as an alternative value to operate the required character using the regex method. The test, search, and match method works...
15 min read
The drawing of the circle is an important functionality of the JavaScript language. JavaScript is a web application programming language to operate functions. The javascript function is used to add required functionalities on the web pages. We created the empty and filled circle on a web page...
6 min read
What is the definition of type conversion? When a value is transformed from one type to the other, it is called type conversion. The types of values in JavaScript are diverse. One could possess a numerical value, a string, an object, a Boolean, or any combination. To fit...
6 min read
Reusable code can help developers create applications. Reusing code does not mean using it without the JavaScript function. Code segments are run at runtime by functions. The normal and Arrow functions are the two main uses of JS. In this article, we will discuss the difference between...
10 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India