回答編集履歴

1

情報の追加。

2019/09/01 17:44

投稿

kei344
kei344

スコア69416

test CHANGED
@@ -17,3 +17,47 @@
17
17
  【data-* - HTML: HyperText Markup Language | MDN】
18
18
 
19
19
  [https://developer.mozilla.org/ja/docs/Web/HTML/Global_attributes/data-*](https://developer.mozilla.org/ja/docs/Web/HTML/Global_attributes/data-*)
20
+
21
+
22
+
23
+ ---
24
+
25
+
26
+
27
+ **追記:**
28
+
29
+
30
+
31
+
32
+
33
+ ```JavaScript
34
+
35
+ var num = Math.floor( Math.random() * 5 ) + 1;
36
+
37
+ var $container = $( '.box-container' );
38
+
39
+ for ( var i = 1; i <= 5; i++ ) {
40
+
41
+ $container.append( '<div class="box" data-num="' + i + '"></div>' );
42
+
43
+ }
44
+
45
+ $container.on( 'click', '.box', function () {
46
+
47
+ if ( $( this ).data( 'num' ) === num ) $( this ).text( 'win' ).addClass( 'win' );
48
+
49
+ $( '.box', $container ).not( '.win' ).text( 'lose' ).addClass( 'lose' );
50
+
51
+ } );
52
+
53
+ ```**動くサンプル:**[https://jsfiddle.net/fmbh0crj/](https://jsfiddle.net/fmbh0crj/)
54
+
55
+
56
+
57
+ ---
58
+
59
+
60
+
61
+ 【.not() | jQuery API Documentation】
62
+
63
+ [https://api.jquery.com/not/](https://api.jquery.com/not/)