LearnFrenzy
Sign in Take a free test

DOM Manipulation · Predict the Output · Question 6

An input's value property and attribute Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

The page contains this HTML:

<input id="q" value="old">

What does the following JavaScript code print when it runs on this page?

main.js
const q = document.getElementById("q");
q.value = "new";
console.log(q.value, q.getAttribute("value"), q.defaultValue);
  • A new new new
  • B old old old
  • C new new old
  • D new old old Correct
Correct Answer: Option D

Setting the property changes the live value only; the attribute (and defaultValue, which reflects it) stays "old".

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links