crmpicco
crmpicco

Reputation: 17181

TypeError: Property '$' of object [object Object] is not a function in jQuery 1.7.2

I am seeing a number of these errors in my JavaScript error logs:

Object expected

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

Unfortunately, I cannot replicate the error on any of these browsers when I try it myself. The line that I have highlighted is the one that is causing the error.

I have a read a bit about "No Conflict" mode and that may be a problem here, but I can't see what the issue would be by looking at the code that is below.

I am using jQuery 1.7.2 and it is served up from my server, rather than a CDN:

<script type="text/javascript" src="/scripts/jquery/jquery-1.7.2.min.js"></script>

My code:

$(function() {

    $('.imgCell').live("mouseenter", function() {
        if($(this).find('a img').length > 1) { // this line throws the error
            $(this).find('a img:eq(0)').hide();
        }   
    });

});

It does not appear to be affecting one specific browser either, as the following are affected: Chrome 26, Chromium 25, Firefox 10, Firefox 14, Firefox 16, Firefox 20, IE 10, IE 8, IE 9, Mobile Safari 6

Upvotes: 1

Views: 6590

Answers (2)

Ravi Gadag
Ravi Gadag

Reputation: 15881

As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers.

$(document).on("mouseenter",'.imgCell', function() {
        //do something
    });

if you're using CDN, then you need to write fallback for it

<script type="text/javascript" src="//ajax.microsoft.com/ajax/jquery/jquery-1.9.2.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined') { // load your JS file if CDN failed 
    document.write(unescape("%3Cscript src='/js/jquery-1.9.2.min.js' type='text/javascript'%3E%3C/script%3E"));   
}
</script>

Upvotes: 1

dev
dev

Reputation: 11

use 'jQuery' instead of $ sign for example

jQuery(this).find('a img').length > 1

Upvotes: 0

Related Questions