For example, the initial value of the input is the value attribute. When the input value is changed, the changed value becomes the value of the value attribute. [Getting example] let data =document.getElementById("xxx").value; [Setting example] document.getElementById("xxx").value = "initial value";
Also, to get the value attribute, which is the value before the change, use the defaultValue property. By the way, you can change the defaultValue property directly. (Example) document.getElementById("xxx").defaultValue = "change value";
innerText
Gets and sets values that can be changed by the user, such as input. This is the range that is visible in the browser, and values that are hidden cannot be obtained. (Example) Text that is hidden by CSS style For example, display: none is not included.
<br> is included in the output. Only the text that is actually displayed is obtained
Script tags that implement javascript are not included.
When a value is set with innerText, all nodes including child elements are deleted and then the text node set with innerText is added.
HTML escape target strings are set after conversion processing. (Example)
<
<
>
>
textContent
Gets and sets text (not including tags). The range is the text content within the element (including all child elements). Gets hidden elements that are not rendered. <br> is not included.
function test()
{
let p =document.getElementById("p");
p.textContent="changeValue";
}
Elements hidden by CSS style For example, settings such as display : none will not be included. Faster processing speed than innerText.
innerHTML
innerHTML
Gets and sets HTML as is. The range is all content within the element.
Since it is possible to insert HTML from outside, there is a security risk. (Example) Since it is possible to insert data from outside using innerHTML, there is a risk of XSS (cross-site scripting) attacks. For this reason, implementations that allow user input to be set directly in innerHTML should be avoided.
outerHTML
Gets and changes the element itself. Similar to innerHTML, but gets and changes the entire HTML including the element itself. The specified element itself is also subject to change. Depending on how it is used, the element may be deleted.
Properties
HTML Tags
Hidden Elements
Example
innerText
Don't get
Don't get
Get and change visible text
textContent
Don't get
Get
Get and change all text
innerHTML
Get
Get
Get and change HTML
outerHTML
Get
Get
Get and change all elements (including the element itself)