HTMLOutputElement: defaultValue property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since August 2016.
The defaultValue
property of the HTMLOutputElement
interface represents the default text content of this element. Getting and setting this value is equivalent to getting and setting
textContent
on the .
Value
A string.
Examples
In the example below, the defaultValue
still returns the value originally written in the HTML. Changes to value
will not affect the defaultValue
or its textContent
in the DOM.
html
js
const logs = document.getElementById("logs");
const operand1 = document.getElementById("operand1");
const operand2 = document.getElementById("operand2");
const result = document.getElementById("result");
function updateResult() {
result.value = operand1.valueAsNumber + operand2.valueAsNumber;
logs.innerText = `result.defaultValue: ${result.defaultValue}\nresult.value: ${result.value}`;
}
operand1.addEventListener("input", updateResult);
operand2.addEventListener("input", updateResult);
updateResult();
Specifications
Specification |
---|
HTML # dom-output-defaultvalue-dev |