Programming in HTML5 with JavaScript and CSS3 — Question 50

You are developing a customer web form that includes the following HTML.
<label id="txtValue"X/label>
Information from the web form is submitted to a web service. The web service returns the following JSON object.
{
"Confirmation": "1234",
"FirstName": "John"
}
You need to display the Confirmation number from the JSON response in the txtValue label field.
Which JavaScript code segment should you use?

Answer options

Correct answer: D

Explanation

The correct answer is D because the .text() method is used to set the text content of an element in jQuery. The other options are incorrect as they either misuse the .val() method, which is for input elements, or incorrectly use the assignment operator instead of the method syntax.