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

回答編集履歴

1

hasClassを使い、書き直しました。

2017/01/17 09:42

投稿

namimon
namimon

スコア726

answer CHANGED
@@ -1,15 +1,18 @@
1
1
  一応動作しましたが、汚くなってしまいました・・・
2
2
  他のベストアンサーを待ちたいです。
3
+
4
+ kei344様ありがとうございます。
5
+ 書き直しました。
6
+
3
7
  ```ここに言語を入力
4
-
5
8
  $('.menu img').mouseover(function() {
6
- if( $(this).parent().parent().attr("class") != "is_active" ) {
9
+ if( !$(this).parents().hasClass("is_active" ) ) {
7
10
  $(this).attr('src', $(this).attr("src").replace(".png", "_on.png"));
8
11
  }
9
12
  });
10
13
 
11
14
  $('.menu img').mouseout(function() {
12
- if( $(this).parent().parent().attr("class") != "is_active" ) {
15
+ if( !$(this).parents().hasClass("is_active" ) ) {
13
16
  $(this).attr('src', $(this).attr('src').replace('_on.png', '.png'));
14
17
  }
15
18
  });