XML DOMLesson 38Free preview
DOM Get Values
This lesson is part of XML · All levels
Summary
The value of the node is taken with the textContent for all the text in it, or the innerHTML that comes with the markup. Attributes are read with getAttribute. When displaying user data to a page, avoid innerHTML because of the risk of XSS; use textContent when only plain text is required.
Key points
- TextContent returns all the node-descended text
- InnerHTML includes HTML tags within the element
- GetAttribute reads the value of the element attribute
- Use of innerHTML on user data is at risk of XSS
- TextContent is safer to insert plain text
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.