element.toggleAttribute(attributeName)
element.toggleAttribute(attributeName, force)
<input type="text">
<button type="button">Hide/Show Input Box</button>
const elem = document.querySelector("input");
const button = document.querySelector("button");

button.addEventListener("click", () => { // Button click event
    // Adds the hidden attribute if it does not exist; otherwise removes it
    elem.toggleAttribute("hidden");
});
Rendered Output Click the "Hide/Show Input Box" button!
<input type="text">
<button type="button">Hide/Show Input Box</button>
<p style="color: red;">
    The status of the hidden attribute will be displayed here.
</p>
button.addEventListener("click", () => { // Button click event
    if (inputElem.toggleAttribute("hidden")) { // If the hidden attribute is added
        msgElem.textContent = "The hidden attribute has been added.";
    } else { // If the hidden attribute is removed
        msgElem.textContent = "The hidden attribute has been removed.";
    }
});
Rendered Output Click the "Hide/Show Input Box" button!
<input type="text">
<button type="button">Hide/Show Input Box</button>
button.addEventListener("click", () => { // Button click event
    if (elem.hasAttribute("hidden")) { // Check whether the hidden attribute exists
        elem.toggleAttribute("hidden", false); // Forcefully remove the hidden attribute
    } else {
        elem.toggleAttribute("hidden", true); // Forcefully add the hidden attribute
    }
});
Rendered Output Click the "Hide/Show Input Box" button!