MDN self-hosted library · e01.org

Element: toggleAttribute() method

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<input value="text" /> <button>toggleAttribute("disabled")</button>
js
const button = document.querySelector("button");
const input = document.querySelector("input");

button.addEventListener("click", () => {
  input.toggleAttribute("disabled");
});