回答編集履歴

4

検証済のコードに修正

2018/10/27 02:54

投稿

think49
think49

スコア18166

test CHANGED
@@ -2,15 +2,73 @@
2
2
 
3
3
 
4
4
 
5
- 以下、未検証。
5
+ ~~以下、未検証。~~
6
-
7
- http://api.jquery.com/attr/#attr-attributeName-function
8
6
 
9
7
 
10
8
 
11
- ```JavaScript
9
+ **(2018/10/27 11:54追記)**
12
10
 
11
+ 検証済のコードに修正しました。
12
+
13
+
14
+
15
+ - [jQuery#atttr( attributeName, function ) - JSFiddle](http://jsfiddle.net/Lm9xkhrs/)
16
+
17
+ - [.attr() | jQuery API Documentation](http://api.jquery.com/attr/#attr-attributeName-function)
18
+
19
+
20
+
21
+ ```HTML
22
+
23
+ <div class="sp-slide">
24
+
25
+ <a href="./img/01.jpg" title="オーバーレイ時のキャプション">
26
+
27
+ <img class="sp-image" src="https://placehold.jp/3d4070/ffffff/150x150.png?text=%E5%86%99%E7%9C%9F1" data-src="./img/01.jpg" data-retina="./img/01.jpg">
28
+
29
+ </a>
30
+
31
+ <p class="sp-layer sp-black sp-padding">写真1の説明文が入ります</p><!--メイン画像表示中のキャプション-->
32
+
33
+ </div>
34
+
35
+
36
+
37
+ <div class="sp-slide">
38
+
39
+ <a href="./img/02.jpg" title="オーバーレイ時のキャプション">
40
+
41
+ <img class="sp-image" src="https://placehold.jp/3d4070/ffffff/150x150.png?text=%E5%86%99%E7%9C%9F2" data-src="./img/02.jpg" data-retina="./img/02.jpg">
42
+
43
+ </a>
44
+
45
+ <p class="sp-layer sp-black sp-padding">写真2の説明文が入ります</p><!--メイン画像表示中のキャプション-->
46
+
47
+ </div>
48
+
49
+
50
+
51
+ <div class="sp-slide">
52
+
53
+ <a href="./img/03.jpg" title="オーバーレイ時のキャプション">
54
+
55
+ <img class="sp-image" src="https://placehold.jp/3d4070/ffffff/150x150.png?text=%E5%86%99%E7%9C%9F3" data-src="./img/03.jpg" data-retina="./img/03.jpg">
56
+
57
+ </a>
58
+
59
+ <p class="sp-layer sp-black sp-padding">写真3の説明文が入ります</p><!--メイン画像表示中のキャプション-->
60
+
61
+ </div>
62
+
63
+
64
+
65
+ <script>
66
+
67
+ 'use strict';
68
+
13
- jQuery('.sp-slide>a').attr('title', function () { return jQuery('.sp-layer', this).text(); });
69
+ jQuery('.sp-slide>a').attr('title', function () { return this.nextElementSibling.textContent; });
70
+
71
+ </script>
14
72
 
15
73
  ```
16
74
 

3

jQuery('.sp-slide>a')

2018/10/27 02:54

投稿

think49
think49

スコア18166

test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  ```JavaScript
12
12
 
13
- jQuery('.sp-slide>a>.sp-layer').attr('title', function () { return this.textContent; });
13
+ jQuery('.sp-slide>a').attr('title', function () { return jQuery('.sp-layer', this).text(); });
14
14
 
15
15
  ```
16
16
 

2

アロー関数 -> 関数式

2018/10/26 12:54

投稿

think49
think49

スコア18166

test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  ```JavaScript
12
12
 
13
- jQuery( '.sp-slide>a>.sp-layer').attr('title', () => this.textContent);
13
+ jQuery('.sp-slide>a>.sp-layer').attr('title', function () { return this.textContent; });
14
14
 
15
15
  ```
16
16
 

1

typo修正

2018/10/26 03:55

投稿

think49
think49

スコア18166

test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  ```JavaScript
12
12
 
13
- jQuery( '.sp-slide>a>.sp-layer'').attr('title', () => this.textContent);
13
+ jQuery( '.sp-slide>a>.sp-layer').attr('title', () => this.textContent);
14
14
 
15
15
  ```
16
16