
163 views
JavaScript hide elements
To hide elements using JavaScript, you can manipulate the CSS display
property of the element. Here are a few ways to achieve it:
Using inline style:
JavaScript
document.getElementById("elementId").style.display = "none";
Using CSS classes:
JavaScript
document.getElementById("elementId").classList.add("hidden");
CSS:
CSS
.hidden {
display: none;
}
Using CSS display
property directly:
JavaScript
document.getElementById("elementId").style.display = "none";
These methods allow you to hide elements by setting the display
property to “none”, effectively removing the element from the visible layout. You can apply these methods to any HTML element by selecting it using its id
, class
, or other selectors.
Remember to use the appropriate method based on your requirements and project structure.