“TypeError: $(…) is null” What's Going On?

谁说我不能喝 提交于 2019-12-23 13:12:21

问题


Firebug is giving the error:

TypeError: $(...) is null
$('#menu img').hover(

I have no idea why. The seemingly problematic script is this which replaces an image when the cursor hovers over an image:

$(document).ready(function()
{
    var storeNormalPath;
    $('#menu img').hover(
        function()
        {   
            storeNormalPath = $(this).attr('src');
            var imgArray = $(this).attr('src').split('.jpg');
            $(this).attr('src', imgArray[0]+'Hover.jpg');
        }, 
        function() 
        {   
            $(this).attr('src', storeNormalPath);
        }
        ).click (function()
        {
            //empty now
        });
});

回答1:


After some looking over your page using chrome's console, it looks that even $(document) is returning null. jQuery(document) however, works, which suggests there is something in conflict with jQuery's $ operator.

(Source: I would direct you to this question: $.document is null)

Seeing that you have both jquery-1.5.1.min.js AND jquery.1.4.2.js referenced in your page header, perhaps that could be the reason of the conflict? Have you tried loading only one of them?

Let us know if that helps, sorry I couldn't be more help. Good luck!



来源:https://stackoverflow.com/questions/16171681/typeerror-is-null-whats-going-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!