开发者

Uncaught TypeError: Property '$' of object [object DOMWindow] is not a function

开发者 https://www.devze.com 2023-03-27 04:44 出处:网络
I am getting an : Uncaught TypeError: Property \'$\' of object [object DOMWindow] is no开发者_StackOverflowt a function error in Chrome with my script.

I am getting an : Uncaught TypeError: Property '$' of object [object DOMWindow] is no开发者_StackOverflowt a function error in Chrome with my script.

<script type="text/javascript"> 
    function showSlidingDiv() {
        $("#slidingDiv").fadeToggle("slow", "linear");
    }
    function showSlidingDiv2() {
        $("#slidingDiv2").fadeToggle("slow", "linear");
    }         
    function showSlidingDiv3() {
        $("#slidingDiv3").fadeToggle("slow", "linear");
    }
</script> 

Does anyone know what could be wrong here?


Chrome does load other libraries that make the use of $ symbol on other purposes, so you have to use jquery no conflict. on of the way is to change the $ symbol with jQuery

$(function(){...});

change to

jQuery(function(){...});


My guess is that jquery was not loaded before run of one of these methods, so or it's not included before run of these methods, or there's some error causing it to not load properly. Normally this should "just work" (at least not throw that kind of error message)

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript"> 
    function showSlidingDiv() {
        $("#slidingDiv").fadeToggle("slow", "linear");
    }
    function showSlidingDiv2() {
        $("#slidingDiv2").fadeToggle("slow", "linear");
    }         
    function showSlidingDiv3() {
        $("#slidingDiv3").fadeToggle("slow", "linear");
    }
</script> 


No mather the time.. I found a solution that worked for me.

Instead of

$("#slidingDiv")

try

jQuery("#slidingDiv")

the other options weren´t usefull for me.


<script type="text/javascript"> 
var j = jQuery;
function showSlidingDiv() {
    j("#slidingDiv").fadeToggle("slow", "linear");
}
function showSlidingDiv2() {
    j("#slidingDiv2").fadeToggle("slow", "linear");
}         
function showSlidingDiv3() {
    j("#slidingDiv3").fadeToggle("slow", "linear");
}
</script> 


make sure jQuery.noConflict() isn't being called. Calling it won't allow the use of the $ shorthand notation.

0

精彩评论

暂无评论...
验证码 换一张
取 消