document.querySelector utility to find an HTML button element and add a
disabled attribute to it.
document.querySelector("button").disabled = true;
This is a nice one-line solution however if there are multiple buttons on the page it might not deliver the behaviour we want. On top of that if we want to enable the button again we would have to write the entire
querySelector utility again, unnecessarily bloating the code.
A more robust solution would be to put an
id attribute on the HTML button element that should be disabled, select it using the
getElementById utility and store the element in a constant.
const button = document.getElementById("send");
Now we can easily enable or disable the button like this:
button.disabled = true; button.disabled = false;