質問編集履歴

6

解決後の報告

2018/04/10 07:22

投稿

murabito
murabito

スコア108

test CHANGED
File without changes
test CHANGED
@@ -71,3 +71,43 @@
71
71
  // target.childNodes[0].nodeValue = "ddd";
72
72
 
73
73
  ```
74
+
75
+
76
+
77
+ # 解決後の報告
78
+
79
+
80
+
81
+ 監視対象をテキストノードにすることで、最後の部分でログ出力の結果が`characterData`となりました。
82
+
83
+
84
+
85
+ ```
86
+
87
+ const target = document.getElementById('test').childNodes[0];
88
+
89
+
90
+
91
+ const observer = new MutationObserver((mutations) => {
92
+
93
+ mutations.forEach((mutation) => {
94
+
95
+ console.log(mutation.type);
96
+
97
+ });
98
+
99
+ });
100
+
101
+
102
+
103
+ const config = { attributes: true, childList: true, characterData: true };
104
+
105
+
106
+
107
+ observer.observe(target, config);
108
+
109
+
110
+
111
+ target.textContent = "eee"; // "characterData"
112
+
113
+ ```

5

// target.innerText = "aaa";

2018/04/10 07:22

投稿

murabito
murabito

スコア108

test CHANGED
File without changes
test CHANGED
@@ -56,6 +56,8 @@
56
56
 
57
57
  //target.textContent = "555";
58
58
 
59
+ // target.innerText = "aaa";
60
+
59
61
 
60
62
 
61
63
  // (質問) これらのいずれかを有効にすれば、どれでもテキストは変わる。
@@ -64,8 +66,6 @@
64
66
 
65
67
 
66
68
 
67
- // target.innerText = "aaa";
68
-
69
69
  // target.childNodes[0].textContent = "ddd";
70
70
 
71
71
  // target.childNodes[0].nodeValue = "ddd";

4

https://developer.mozilla.org/ja/docs/Web/API/MutationObs

2018/04/10 07:20

投稿

murabito
murabito

スコア108

test CHANGED
@@ -1 +1 @@
1
- https://developer.mozilla.org/ja/docs/Web/API/MutationObsJSのWeb APIのMutationObserverで要素のテキスト変更を監視したい
1
+ JSのWeb APIのMutationObserverで要素のテキスト変更を監視したい
test CHANGED
File without changes

3

https://developer.mozilla.org/ja/docs/Web/API/MutationObserver

2018/04/10 07:01

投稿

murabito
murabito

スコア108

test CHANGED
@@ -1 +1 @@
1
- JSのWeb APIのMutationObserverで要素のテキスト変更を監視したい
1
+ https://developer.mozilla.org/ja/docs/Web/API/MutationObsJSのWeb APIのMutationObserverで要素のテキスト変更を監視したい
test CHANGED
@@ -1,4 +1,4 @@
1
- Web APIのMutationObserverを試しているのですが、ある要素のテキストの変更の監視が上手く出来ません。
1
+ Web APIの[MutationObserver](https://developer.mozilla.org/ja/docs/Web/API/MutationObserver)を試しているのですが、ある要素のテキストの変更の監視が上手く出来ません。
2
2
 
3
3
 
4
4
 

2

`characterData`を`true`にしているので大丈夫かなと思ったのですが、上手くいきません。

2018/04/10 07:00

投稿

murabito
murabito

スコア108

test CHANGED
File without changes
test CHANGED
@@ -5,6 +5,8 @@
5
5
  以下が試してみたコードなのですが、なぜ、最後の3行のはどれも値自体はページ上で変更を確認できるのに、通知が来ないのでしょうか?
6
6
 
7
7
 
8
+
9
+ `characterData`を`true`にしているので大丈夫かなと思ったのですが、上手くいきません。
8
10
 
9
11
 
10
12
 

1

childList: true

2018/04/10 06:59

投稿

murabito
murabito

スコア108

test CHANGED
File without changes
test CHANGED
@@ -34,7 +34,7 @@
34
34
 
35
35
 
36
36
 
37
- const config = { attributes: true, childList: false, characterData: true };
37
+ const config = { attributes: true, childList: true, characterData: true };
38
38
 
39
39
 
40
40