回答編集履歴
1
情報の追加。
answer
CHANGED
@@ -7,4 +7,26 @@
|
|
7
7
|
```
|
8
8
|
|
9
9
|
【data-* - HTML: HyperText Markup Language | MDN】
|
10
|
-
[https://developer.mozilla.org/ja/docs/Web/HTML/Global_attributes/data-*](https://developer.mozilla.org/ja/docs/Web/HTML/Global_attributes/data-*)
|
10
|
+
[https://developer.mozilla.org/ja/docs/Web/HTML/Global_attributes/data-*](https://developer.mozilla.org/ja/docs/Web/HTML/Global_attributes/data-*)
|
11
|
+
|
12
|
+
---
|
13
|
+
|
14
|
+
**追記:**
|
15
|
+
|
16
|
+
|
17
|
+
```JavaScript
|
18
|
+
var num = Math.floor( Math.random() * 5 ) + 1;
|
19
|
+
var $container = $( '.box-container' );
|
20
|
+
for ( var i = 1; i <= 5; i++ ) {
|
21
|
+
$container.append( '<div class="box" data-num="' + i + '"></div>' );
|
22
|
+
}
|
23
|
+
$container.on( 'click', '.box', function () {
|
24
|
+
if ( $( this ).data( 'num' ) === num ) $( this ).text( 'win' ).addClass( 'win' );
|
25
|
+
$( '.box', $container ).not( '.win' ).text( 'lose' ).addClass( 'lose' );
|
26
|
+
} );
|
27
|
+
```**動くサンプル:**[https://jsfiddle.net/fmbh0crj/](https://jsfiddle.net/fmbh0crj/)
|
28
|
+
|
29
|
+
---
|
30
|
+
|
31
|
+
【.not() | jQuery API Documentation】
|
32
|
+
[https://api.jquery.com/not/](https://api.jquery.com/not/)
|