回答編集履歴
2
軽微な書式の変更
test
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
|
31
31
|
|
32
32
|
|
33
|
-
```
|
33
|
+
```js
|
34
34
|
|
35
35
|
const nodeIterator = document.createNodeIterator(
|
36
36
|
|
1
質問を勘違いしていたので追記
test
CHANGED
@@ -11,3 +11,55 @@
|
|
11
11
|
$( "p:contains('000-1166-0000')" ).addClass('Klass')
|
12
12
|
|
13
13
|
```
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
---
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
# 質問を勘違いしていたので追記
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
NodeIterator がいいかもしれないですね。
|
28
|
+
|
29
|
+
[NodeIterator - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/NodeIterator)
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
const nodeIterator = document.createNodeIterator(
|
36
|
+
|
37
|
+
document.body,
|
38
|
+
|
39
|
+
NodeFilter.SHOW_TEXT,
|
40
|
+
|
41
|
+
{
|
42
|
+
|
43
|
+
acceptNode: function (node) {
|
44
|
+
|
45
|
+
return /\d{3}-\d{4}-\d{4}/.test(node.nodeValue) ?
|
46
|
+
|
47
|
+
NodeFilter.FILTER_ACCEPT :
|
48
|
+
|
49
|
+
NodeFilter.FILTER_REJECT;
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
);
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
while ((node = nodeIterator.nextNode())) {
|
60
|
+
|
61
|
+
node.parentNode.classList.add('Klass');
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
```
|