回答編集履歴

1

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

2017/01/17 09:42

投稿

namimon
namimon

スコア726

test CHANGED
@@ -2,13 +2,19 @@
2
2
 
3
3
  他のベストアンサーを待ちたいです。
4
4
 
5
+
6
+
7
+ kei344様ありがとうございます。
8
+
5
- ```ここに言語を入力
9
+ 書き直しました。
6
10
 
7
11
 
8
12
 
13
+ ```ここに言語を入力
14
+
9
15
  $('.menu img').mouseover(function() {
10
16
 
11
- if( $(this).parent().parent().attr("class") != "is_active" ) {
17
+ if( !$(this).parents().hasClass("is_active" ) ) {
12
18
 
13
19
  $(this).attr('src', $(this).attr("src").replace(".png", "_on.png"));
14
20
 
@@ -20,7 +26,7 @@
20
26
 
21
27
  $('.menu img').mouseout(function() {
22
28
 
23
- if( $(this).parent().parent().attr("class") != "is_active" ) {
29
+ if( !$(this).parents().hasClass("is_active" ) ) {
24
30
 
25
31
  $(this).attr('src', $(this).attr('src').replace('_on.png', '.png'));
26
32