回答編集履歴

3

chousei

2021/03/26 10:40

投稿

yambejp
yambejp

スコア117601

test CHANGED
@@ -25,3 +25,11 @@
25
25
 
26
26
 
27
27
  ```
28
+
29
+
30
+
31
+ ```CSS
32
+
33
+ .error:not(.on){display:none;}
34
+
35
+ ```

2

chousei

2021/03/26 10:40

投稿

yambejp
yambejp

スコア117601

test CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  }
14
14
 
15
- if(n=x.closest('div').querySelector('input[type=radio]:checked')){
15
+ if(x.closest('div').querySelector('input[type=radio]:checked')){
16
16
 
17
17
  x.classList.remove('on');
18
18
 

1

chousei

2021/03/26 10:38

投稿

yambejp
yambejp

スコア117601

test CHANGED
@@ -1,14 +1,4 @@
1
1
  ```javascript
2
-
3
- window.addEventListener('DOMContentLoaded', ()=>{
4
-
5
- document.querySelectorAll('.error').forEach(x=>{
6
-
7
- x.dataset.error=x.textContent;
8
-
9
- });
10
-
11
- });
12
2
 
13
3
  document.addEventListener('input',e=>{
14
4
 
@@ -18,13 +8,13 @@
18
8
 
19
9
  if(n=x.closest('div').querySelector('input[type=text]')){
20
10
 
21
- x.textContent=n.value?"":x.dataset.error;
11
+ x.classList.toggle('on',n.value=="");
22
12
 
23
13
  }
24
14
 
25
15
  if(n=x.closest('div').querySelector('input[type=radio]:checked')){
26
16
 
27
- x.textContent="";
17
+ x.classList.remove('on');
28
18
 
29
19
  }
30
20
 
@@ -32,4 +22,6 @@
32
22
 
33
23
  });
34
24
 
25
+
26
+
35
27
  ```