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

回答編集履歴

2

調整

2019/09/09 10:50

投稿

yambejp
yambejp

スコア117923

answer CHANGED
@@ -18,4 +18,16 @@
18
18
 
19
19
  <div class="sample">りんご</div>
20
20
  <div class="sample2">あるみかん</div>
21
+ ```
22
+
23
+ # addClassとの組み合わせ
24
+ ```javascript
25
+ $(function(){
26
+ $('.sample').filter(function(){return $(this).text().match(/りんご/);}).addClass('apple');
27
+ $('.sample2').filter(function(){return $(this).text().match(/みかん/);}).addClass('orange');
28
+ $('.sample').filter(function(){return $(this).text().match(/ぶどう/);}).addClass('grape')
29
+ });
30
+ </script>
31
+ <div class="sample">りんご</div>
32
+ <div class="sample2">あるみかん</div>
21
33
  ```

1

ちょうせい

2019/09/09 10:49

投稿

yambejp
yambejp

スコア117923

answer CHANGED
@@ -10,6 +10,9 @@
10
10
  if($('.sample2').filter(function(){return $(this).text().match(/みかん/);}).length>0){
11
11
  console.log('みかん'); //ヒットする
12
12
  }
13
+ if($('.sample').filter(function(){return $(this).text().match(/ぶどう/);}).length>0){
14
+ console.log('ぶどう'); //ヒットしない
15
+ }
13
16
  });
14
17
  </script>
15
18