When I tried searching for this specific wording I found a lot of related questions on stackoverflow, but not this one. I figured it out from other posts and what I already know, but since I did not find this specific question clearly asked in stackoverflow, I hope this helps someone less experienced find the answer.
You should be looking for the value of the
disabled property of the HTML element instead of the attribute.
disabled is both an attribute and a property, but only the property is really useful. You get it in your js like this:
let myElement = document.document.getElementsByTagName('input'); let is_disabled = myElement.disabled; // true or false
The MDN page on
disabled is no help. It only talks about
disabled as an attribute. Maybe there is another page in the MDN that I have not found yet that explains it better.
An attribute has to do with HTML. In the code below,
class is an attribute:
It has a value right there in the HTML. You get the value of an attribute with
let classNames = myElement.getAttribute('class'); // "the-best"
let inner_height = myElement.clientHeight; // Some number
disabled looks like this:
You can see
disabled in the HTML, but it does not have a value. You can give it a value, like
myElement.setAttribute('disabled', 'false'). You’ll get
<input disabled="false"> and the element will be disabled. If
disabled is in the HTML the element is disabled. If it is not in the HTML then the element is NOT disabled.
.getAttribute() will work like this:
// <input disabled/> let is_disabled = myElement.getAttribute('disabled'); // "" - an empty string
// <input/> let is_disabled = myElement.getAttribute('disabled'); // null
You can probably still use
.getAttribute() if you want since you can check for a
null, but people sometimes do weird things with their HTML and the “values” of these kinds of attributes (like what I described above).