...
*/!* - div.outerHTML = 'A new element!
'; // (*) + div.outerHTML = 'A new element
'; // (*) *!* // Wow! The div is still the same! */!* - alert(div.outerHTML); //...
`. In the outer document we can see the new content instead of the `A new element
`. In the outer document we can see the new content instead of the `A new element
` was inserted instead. +- `div` still has the old value. The new HTML wasn't saved to any variable. -We can write to `outerHTML`, but should keep in mind that it doesn't change the element we're writing to. It creates the new content on its place instead. We can get a reference to new elements by querying DOM. +It's so easy to make an error here: modify `div.outerHTML` and then continue to work with `div` as if it had the new content in it. But it doesn't. Such thing is correct for `innerHTML`, but not for `outerHTML`. + +We can write to `elem.outerHTML`, but should keep in mind that it doesn't change the element we're writing to. It creates the new HTML on its place instead. We can get references to new elements by querying DOM. ## nodeValue/data: text node content The `innerHTML` property is only valid for element nodes. -Other node types have their counterpart: `nodeValue` and `data` properties. These two are almost the same for practical use, there are only minor specification differences. So we'll use `data`, because it's shorter. +Other node types, such as text nodes, have their counterpart: `nodeValue` and `data` properties. These two are almost the same for practical use, there are only minor specification differences. So we'll use `data`, because it's shorter. An example of reading the content of a text node and a comment: @@ -345,7 +349,9 @@ An example of reading the content of a text node and a comment: