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 Data structures and algorithms structure the foundation of software engineering and programming. They are fundamental apparatuses for taking care of complicated issues productively and are urgent in building vigorous and versatile applications. In this masterclass, we will dive into the universe of JavaScript algorithms and data...
19 min read
To compare two values and see if they are equal in JavaScript, use the equality operator. The tight equality operator (===) and the loose equality operator (==) are the two different kinds of equality operators in JavaScript. The way these operations handle different data types...
4 min read
2 Dimensional Array A two-dimensional array, also known as a 2D array, is an array of arrays. It's essentially a table of data organized into rows and columns. Each element of the array holds another array, effectively creating rows and columns. For example, consider a 2D array representing...
6 min read
1285 Primitive values in JavaScript and other object-oriented programming languages are divide of methods and attributes. They must be transformed into object data types via a wrapper in order to be used. The most basic building blocks of a computer language are primitive data types. There...
6 min read
What is Data Structure in JavaScript? In JavaScript, a data structure is a format to organize, manage, and store data in a way that helps us to get access to and modification of data. In simple words, a data structure is a collection of data values and...
11 min read
JavaScript regex source property helps to return the source code or format of the regular expression. We can get the regular expression pattern used for the operation and validation. Syntax The following syntax is used to get the regular expression's pattern. regexObject.source; Supported Browsers The browsers supported by RegExp source...
7 min read
What is Hashmap in JavaScript? In JavaScript, Hashmap is an important data structure that helps us to store and retrieve key-value pairs efficiently. With the use of Hashmap, we can provide quick access to values which is based on their keys which are commonly used to optimize...
6 min read
One of the most powerful features of JavaScript is that it can change the styling of elements in a webpage. You can maintain a dynamic design style by customizing the style of an element using javascript language based on the input or behavior of a user....
6 min read
In JavaScript, typecasting is the process of converting the value of one data type into another data type. For example, converting a data type number to a string. What is the data type? It is a type of data that a variable can hold. There are eight main data...
8 min read
The javascript regex modifier controls and operates input data with the metacharacters and other regular expressions. The modifier works with the metacharacter and quantifiers to get the particular field. The search(), match(), test(), exec() method works with the regex modifier in javascript. The three modifiers...
7 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