Uncaught TypeError: undefined is not a function on loading jquery

I'm building a normal webpage which requires me to load about five CSS files and ten Javascript files.

  • When loading them separately in the HTML page, my webpage loads fine.
  • Now for production, I concatenated all the Javascript into a single file, in the order needed, and all the CSS into another file. But when I try to run the web page with the concatenated files it throws an error saying:

    Uncaught TypeError: undefined is not a function

  • On the line where jquery.min.js is being loaded in the concatenated Javascript file.

    What can I do to mitigate this? I want to concatenate all files and minify them for production. Please help.


    EDIT: I merged the Javascript and CSS in the order they were when they were being loaded individually and were working fine.


    Assuming this problem still has not be resolved, a lot of individual files don't end their code with a semicolon. Most jQuery scripts end with (jQuery) and you need to have (jQuery); .

    As separate files the script will load just fine but as one individual file you need the semicolons.


    You might have to re-check the order in which you are merging the files, it should be something like:

  • jquery.min.js
  • jquery-ui.js
  • any third party plugins you loading
  • your custom JS

  • This solution worked for me

    
        ;(function($){
            // your code
        })(jQuery);
    
    

    Move your code inside the closure and use $ instead of jQuery

    I found the above solution in https://magento.stackexchange.com/questions/33348/uncaught-typeerror-undefined-is-not-a-function-when-using-a-jquery-plugin-in-ma

    after seraching too much

    链接地址: http://www.djcxy.com/p/45704.html

    上一篇: 将数据传递给引导模式

    下一篇: Uncaught TypeError:undefined不是加载jquery的函数