2012-10-09 26 views
1

我正在使用jQuery來更改某些元素的CSS,而將鼠標懸停在其他元素上,並在Chrome開發人員工具中收到此錯誤: 「遺漏的類型錯誤:對象.gearImg有沒有方法 'CSS'」 這裏是我的CSS代碼:得到一個錯誤消息「未捕獲TypeError:對象.gearImg沒有方法'css'」

.gearImg{ 
    position: absolute; 
    z-index: 10; 
    top: 2px; 
    right: 10px; 
    opacity: 0.5; 

} 

這裏是我的jQuery代碼:

$('#settings_div').hover(function(){ 
     $(this).show(); 
     alert(('.gearImg').css('opacity')); //alerting to find the problem, should show 0.5 
    }, 
    function(){ 
     $(this).hide(); 
     ('.gearImg').css('opacity', 0.5); 
    }); 

問題在哪裏?

感謝

回答

3

試試這個請:演示http://jsfiddle.net/VGAv8/

$失蹤-如果你是進一步好奇,是什麼$閱讀本What is the meaning of "$" sign in javascript

其餘部分應符合的原因:)

代碼

$('#settings_div').hover(function(){ 
     $(this).show(); 
     alert($('.gearImg').css('opacity')); //alerting to find the problem, should show 0.5 
    }, 
    function(){ 
     $(this).hide(); 
     $('.gearImg').css('opacity', 0.5); 
    }); 
1

如何擺在面前('.gearImg')jQuery/$
應該jQuery('.gearImg')$('.gearImg')

1

缺少$在選擇前

$('#settings_div').hover(function(){ 
     $(this).show(); 
     alert($('.gearImg').css('opacity')); //alerting to find the problem, should show 0.5 
    }, 
    function(){ 
     $(this).hide(); 
     $('.gearImg').css('opacity', 0.5); 
    }); 
相關問題