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.
ThedefaultValue property of theHTMLOutputElement interface represents the default text content of this<output> element. Getting and setting this value is equivalent to getting and settingtextContent on the<output>.
In this article
Value
A string.
Examples
In the example below, thedefaultValue still returns the value originally written in the HTML. Changes tovalue will not affect thedefaultValue or itstextContent in the DOM.
html
<fieldset> <legend>Add two numbers</legend> <p> <input type="number" value="5" aria-label="First number" /> + <input type="number" value="7" aria-label="Second number" /> = <output for="operand1 operand2" aria-live="polite" aria-controls="output" >12</output > </p></fieldset><pre aria-live="polite"></pre>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> |