teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

書式改善

2019/03/15 04:34

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -7,7 +7,24 @@
7
7
 
8
8
  よろしくお願いいたします。
9
9
 
10
+ ```html
11
+ <body>
12
+ <div class="js-btn1">btn1</div>
13
+ <div class="js-child1">panel1</div>
10
14
 
15
+ <div class="js-btn2">btn2</div>
16
+ <div class="js-child2">panel2</div>
17
+
18
+ <div class="js-btn3">btn3</div>
19
+ <div class="js-child3">pane3</div>
20
+
21
+ <div class="js-btn4">btn4</div>
22
+ <div class="js-child4">panel4</div>
23
+
24
+ </body>
25
+ ```
26
+
27
+
11
28
  ### 該当のソースコード
12
29
 
13
30
  ```ここに言語を入力

2

書式の改善

2019/03/15 02:12

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -14,16 +14,16 @@
14
14
  $(document).ready(function(){
15
15
  $('.js-btn1').click(function(){
16
16
  $(this).next('.js-child1').slideToggle('fast');
17
- }
17
+ })
18
18
  $('.js-btn2').click(function(){
19
19
  $(this).next('.js-child2').slideToggle('fast');
20
- }
20
+ })
21
21
  $('.js-btn3').click(function(){
22
22
  $(this).next('.js-child3').slideToggle('fast');
23
- }
23
+ })
24
24
  $('.js-btn4').click(function(){
25
25
  $(this).next('.js-child4').slideToggle('fast');
26
- }
26
+ })
27
27
  });
28
28
  ```
29
29
 
@@ -34,7 +34,7 @@
34
34
  for (var i = 0; i < 5; i++) {
35
35
  $('.js-btn'+i).click(function(){
36
36
  $(this).next('.js-child'+i).slideToggle('fast');
37
- }
37
+ });
38
38
  }
39
39
  });
40
40
  ```

1

書式の改善、試したコードを追記しました。

2019/03/15 02:09

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -10,6 +10,7 @@
10
10
 
11
11
  ### 該当のソースコード
12
12
 
13
+ ```ここに言語を入力
13
14
  $(document).ready(function(){
14
15
  $('.js-btn1').click(function(){
15
16
  $(this).next('.js-child1').slideToggle('fast');
@@ -23,4 +24,21 @@
23
24
  $('.js-btn4').click(function(){
24
25
  $(this).next('.js-child4').slideToggle('fast');
25
26
  }
26
- });
27
+ });
28
+ ```
29
+
30
+ こちらで試してみたコードは以下になります。
31
+
32
+ ```ここに言語を入力
33
+ $(document).ready(function(){
34
+ for (var i = 0; i < 5; i++) {
35
+ $('.js-btn'+i).click(function(){
36
+ $(this).next('.js-child'+i).slideToggle('fast');
37
+ }
38
+ }
39
+ });
40
+ ```
41
+
42
+ $('.js-btn'+i)や('.js-child'+i)などは正しい記述になりますでしょうか。
43
+
44
+ 初歩的なご質問になり恐縮ですが、よろしくお願い申し上げます。