You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On first and second reading, I found this section very confusing. After looking up outerHTML on Mozilla and doing some tests, I came to understand what was being said (I think). Here I'm proposing some changes to, I hope, make it clearer (plus some little grammar changes).
In the line `(*)` we replaced `div` with `<p>A new element</p>`. In the outer document we can see the new content instead of the `<div>`. But, as we can see in line `(**)`, the old `div` variable is still the same!
313
+
In the line `(*)` we replaced `div` with `<p>A new element</p>`. In the outer document (the DOM) we can see the new content instead of the `<div>`. But, as we can see in line `(**)`, the value of the old `div` variable hasn't changed!
314
314
315
-
The `outerHTML` assignment does not modify the DOM element, but removes it from the outer context and inserts a new piece of HTML instead of it.
315
+
The `outerHTML` assignment does not modify the DOM element (the object referenced by, in this case, the variable 'div'), but removes it from the DOM and inserts the new HTML in its place.
316
316
317
317
So what happened in `div.outerHTML=...` is:
318
318
- `div` was removed from the document.
319
-
- Another HTML `<p>A new element</p>` was inserted instead.
320
-
- `div` still has the old value. The new HTML wasn't saved to any variable.
319
+
- Another piece of HTML `<p>A new element</p>` was inserted in its place.
320
+
- `div` still has its old value. The new HTML wasn't saved to any variable.
321
321
322
322
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`.
323
323
324
-
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.
324
+
We can write to `elem.outerHTML`, but should keep in mind that it doesn't change the element we're writing to ('elem'). It puts the new HTML in its place instead. We can get references to the new elements by querying the DOM.
0 commit comments