Which jQuery method is used to set the text content of an element?
Correct answer
B. text()
16 views
B. text()
16 views
text() sets or returns the text content of the selected elements. $("#msg").text("Hello") sets it; calling text() with no argument reads it.
Use html() when the content includes markup and val() for form fields. textContent is a plain JavaScript property, not a jQuery method.
Keep preparing with more Computer Science MCQs on MCQsExam.com.
Not sure why the answer is B? Ask here and get an explanation.