How to hide an HTML element using JavaScript?

To hide an HTML element using JavaScript, you can use the following methods:

  1. Changing the CSS style of the element to set its display property to "none":
document.getElementById("elementId").style.display = "none";

This method sets the display property to "none" which will hide the element entirely.

  1. Adding a "hidden" attribute to the element:
document.getElementById("elementId").setAttribute("hidden", true);

This method adds a "hidden" attribute to the element, which is a built-in feature in HTML5 that hides the element.

Note: Replace "elementId" with the actual ID of the HTML element you want to hide.