Student-friendly HTML, CSS, and JavaScript reference with examples
Gets or sets the value in an input field.
const input = document.querySelector('input');
// Get what user typed
const userText = input.value;
// Set the input value
input.value = 'Hello!';
// Clear the input
input.value = '';
Use .value for inputs, textareas, and selects.