回答編集履歴

2

調整

2019/09/09 10:50

投稿

yambejp
yambejp

スコア114863

test CHANGED
@@ -39,3 +39,27 @@
39
39
  <div class="sample2">あるみかん</div>
40
40
 
41
41
  ```
42
+
43
+
44
+
45
+ # addClassとの組み合わせ
46
+
47
+ ```javascript
48
+
49
+ $(function(){
50
+
51
+ $('.sample').filter(function(){return $(this).text().match(/りんご/);}).addClass('apple');
52
+
53
+ $('.sample2').filter(function(){return $(this).text().match(/みかん/);}).addClass('orange');
54
+
55
+ $('.sample').filter(function(){return $(this).text().match(/ぶどう/);}).addClass('grape')
56
+
57
+ });
58
+
59
+ </script>
60
+
61
+ <div class="sample">りんご</div>
62
+
63
+ <div class="sample2">あるみかん</div>
64
+
65
+ ```

1

ちょうせい

2019/09/09 10:49

投稿

yambejp
yambejp

スコア114863

test CHANGED
@@ -22,6 +22,12 @@
22
22
 
23
23
  }
24
24
 
25
+ if($('.sample').filter(function(){return $(this).text().match(/ぶどう/);}).length>0){
26
+
27
+ console.log('ぶどう'); //ヒットしない
28
+
29
+ }
30
+
25
31
  });
26
32
 
27
33
  </script>