JS-Dev-101 practice question 9 of 25
A developer creates a simple webpage with an input field. When a user enters text and clicks the button, the actual value must be displayed in the…
Full set: 148 questionsThe getAttribute('value') method retrieves the value of the HTML value attribute as it was defined in the initial page source. It does not reflect the live, current text a user has typed into the input field. To get the current value of an input element, you must use the .value property of the DOM element object. This property always holds the up-to-date content of the form control.
A. addCallback is not a standard DOM method for event handling; the correct method is addEventListener.
B. getElementByIdName is not a valid DOM method. Methods like getElementById or getElementsByName exist, but not this one.
D. The event type for addEventListener is "click". "onclick" is the name of the HTML attribute or object property, not the event type string.
1. MDN Web Docs, HTMLInputElement.value. "The value property of the HTMLInputElement interface gets or sets the current value of the element."
2. MDN Web Docs, Element.getAttribute(). "It is recommended that you use element.value to get the current value of a text input, because the value attribute does not dynamically update as the user types."
3. W3C, HTML Living Standard, Section 4.10.5.1.10 "The value attribute". "The value IDL attribute must reflect the current value of the element."
Keep practicing
Take the free JS-Dev-101 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other JS-Dev-101 practice questions
- Question 1A developer executes: document.cookie; document.cookie = 'key=John Smith'; What is the be…
- Question 2A developer is required to write a function that calculates the sum of elements in an arr…
- Question 3Given the code below: 01 const delay = async delay => { 02 return new Promise((resolve, r…
- Question 401 function Animal(size, type) { 02 this.type = type || 'Animal'; 03 this.canTalk = false…
- Question 5Refer to the code snippet: 01 let array = [1, 2, 3, 4, 4, 5, 4, 4]; 02 for (let i = 0; i …
- Question 6Code: 01 let array = [1, 2, 3, 4, 4, 5, 4, 4]; 02 for (let i = 0; i < array.length; i++) …
