til/textarea-defaultvalue.mdtil
date
2026-11-10
tags
[dom, html]

TIL

A textarea remembers its original text in defaultValue

For a <textarea>, .value is what the user has typed and .defaultValue is the text that was in the HTML. Editing changes .value only, so a “reset” button needs one line:

editor.value = editor.defaultValue;

There’s no need to keep a second copy of the original in a <template> or a data attribute.

↑↓ select ↵ open esc close