Attributes and reflected properties
Quick answer
getAttribute reads an attribute string or null. DOM properties may reflect attributes with a different type. Boolean attributes are true by presence, not by the spelling of their value.
Browser example
Run in a browser document, not a bare Node.js process.
const b=document.createElement("button");b.setAttribute("disabled","false");console.log(b.disabled,b.getAttribute("disabled"));Expected console output:
true falseCommon mistake
disabled="false" still disables the button.
Practice
Enable the button by removing the disabled attribute.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Attributes and reflected properties — Knowledge Check
Check the central concept, apply it to a new scenario, and predict browser behavior.
What makes an HTML boolean attribute active?
How can you enable a button disabled by a disabled attribute?
What does getAttribute return for a missing attribute?
Why can button.disabled and button.getAttribute('disabled') have different types?
What is printed by this browser snippet? (Attributes and reflected properties)
const b=document.createElement("button");b.setAttribute("disabled","");console.log(b.disabled);b.removeAttribute("disabled");console.log(b.disabled,b.getAttribute("disabled")===null);