Revealing a Secret HTML Element Using JavaScript

Posted by

Show Hidden Element with JavaScript

Click the button to show the hidden element

This is a hidden element that will be shown when the button is clicked.

function showElement() {
var element = document.getElementById(‘hiddenElement’);
element.style.display = ‘block’;
}

In this example, we have a simple HTML document with a button and a hidden div element. The div element is initially hidden with the “display: none;” CSS property.

When the button is clicked, the showElement() function is called. This function gets the hidden element by its ID and sets its display property to ‘block’, making it visible on the web page.

This is a simple and common way to show hidden elements using JavaScript. Adding interactivity like this can enhance the user experience on a website and make it more engaging.