回答編集履歴

3

調整

2022/01/04 09:22

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -55,3 +55,61 @@
55
55
  });
56
56
 
57
57
  ```
58
+
59
+
60
+
61
+ # 指定文字を含むものを削除
62
+
63
+ ```javascript
64
+
65
+ <script>
66
+
67
+ window.addEventListener('DOMContentLoaded', ()=>{
68
+
69
+ const list=["カテゴリー2","カテゴリー4"];
70
+
71
+ [...document.querySelectorAll('.breadcrumb__listItem')].forEach(x=>{
72
+
73
+ if(new RegExp(list.join('|')).test(x.textContent)) x.remove();
74
+
75
+ });
76
+
77
+ });
78
+
79
+ </script>
80
+
81
+ <nav class="breadcrumb">
82
+
83
+ <ol class="breadcrumb__list">
84
+
85
+ <li class="breadcrumb__listItem">
86
+
87
+ <a href="">カテゴリー1</a>
88
+
89
+ </li>
90
+
91
+ <li class="breadcrumb__listItem">
92
+
93
+ <a href="">カテゴリー2</a>
94
+
95
+ </li>
96
+
97
+ <li class="breadcrumb__listItem">
98
+
99
+ <a href="">カテゴリー3</a>
100
+
101
+ </li>
102
+
103
+ <li class="breadcrumb__listItem">
104
+
105
+ <a href="">カテゴリー4</a>
106
+
107
+ </li>
108
+
109
+ <li class="breadcrumb__listItem">カテゴリー5</li>
110
+
111
+ </ol>
112
+
113
+ </nav>
114
+
115
+ ```

2

調整

2022/01/04 09:22

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -35,3 +35,23 @@
35
35
  </nav>
36
36
 
37
37
  ```
38
+
39
+
40
+
41
+ # 古い書き方
42
+
43
+ ```javascript
44
+
45
+ window.addEventListener('DOMContentLoaded', function(){
46
+
47
+ const list=["カテゴリー2","カテゴリー4"];
48
+
49
+ [].forEach.call(document.querySelectorAll('.breadcrumb__listItem'),function(x){
50
+
51
+ if(list.indexOf(x.textContent)>-1) x.parentNode.removeChild(x);
52
+
53
+ });
54
+
55
+ });
56
+
57
+ ```

1

調整

2022/01/04 07:35

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
  <li class="breadcrumb__listItem"><a href="">カテゴリー3</a></li>
28
28
 
29
- <li class="breadcrumb__listItem"><a href="">カテゴリー4</a></li>
29
+ <li class="breadcrumb__listItem">カテ<a href="">ゴリ</a>ー4</li> <!--これもヒットさせる-->
30
30
 
31
31
  <li class="breadcrumb__listItem">カテゴリー5</li>
32
32