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
Copy file name to clipboardExpand all lines: 2-ui/99-ui-misc/01-mutation-observer/article.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
4
4
`MutationObserver` is a built-in object that observes a DOM element and fires a callback in case of changes.
5
5
6
-
We'll first see syntax, and then explore a real-world use case.
6
+
We'll first take a look at the syntax, and then explore a real-world use case.
7
7
8
8
## Syntax
9
9
@@ -46,7 +46,7 @@ Then after any changes, the `callback` is executed: changes are passed in the fi
46
46
-`attributeName/attributeNamespace` -- the name/namespace (for XML) of the changed attribute,
47
47
-`oldValue` -- the previous value, only for attribute or text changes, if the corresponding option is set `attributeOldValue`/`characterDataOldValue`.
48
48
49
-
For example, here's a `<div>` with `contentEditable` attribute. That attribute allows us to focus on it and edit.
49
+
For example, here's a `<div>` with a `contentEditable` attribute. That attribute allows us to focus on it and edit.
50
50
51
51
```html run
52
52
<divcontentEditableid="elem">Click and <b>edit</b>, please</div>
@@ -117,7 +117,7 @@ There are also situations when `MutationObserver` is good from architectural sta
117
117
118
118
Let's say we're making a website about programming. Naturally, articles and other materials may contain source code snippets.
119
119
120
-
Such snippet in HTML markup looks like this:
120
+
Such snippet in an HTML markup looks like this:
121
121
122
122
```html
123
123
...
@@ -130,7 +130,7 @@ Such snippet in HTML markup looks like this:
130
130
131
131
Also we'll use a JavaScript highlighting library on our site, e.g. [Prism.js](https://prismjs.com/). A call to `Prism.highlightElem(pre)` examines the contents of such `pre` elements and adds into them special tags and styles for colored syntax highlighting, similar to what you see in examples here, at this page.
132
132
133
-
When exactly to run that highlighting method? We can do it on `DOMContentLoaded` event, or at the bottom of the page. At that moment we have DOM ready, can search for elements `pre[class*="language"]` and call `Prism.highlightElem` on them:
133
+
When exactly to run that highlighting method? We can do it on `DOMContentLoaded` event, or at the bottom of the page. At that moment we have our DOM ready, can search for elements `pre[class*="language"]` and call `Prism.highlightElem` on them:
134
134
135
135
```js
136
136
// highlight all code snippets on the page
@@ -207,7 +207,7 @@ let demoElem = document.getElementById('highlight-demo');
Here's HTML-element and JavaScript that dynamically fills it using `innerHTML`.
210
+
Here's an HTML-element and JavaScript that dynamically fills it using `innerHTML`.
211
211
212
212
Please run the previous code (above, observes that element), and then the code below. You'll see how `MutationObserver` detects and highlights the snippet.
0 commit comments