テキスト入力要素の値を取得するために使用する正しいプロパティはどれですか?
- innerHTML
- value
- textContent
- getAttribute(“text”)
正解
- value
解説
入力要素の値は value プロパティを用いて取得・設定します。innerHTML や textContent は通常の要素の内容を扱うため、フォーム入力値には使えません。
使用例(サンプルコード)
[ javascript ]
let input = document.querySelector("#username");
console.log(input.value);