最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught TypeError: Cannot read property 'noConflict' of undefined - Stack Overflow

programmeradmin0浏览0评论

I'm new to jQuery and I'm getting an error in a web page of mine as follows: "Uncaught TypeError: Cannot read property 'noConflict' of undefined"

I'm using jQuery in my page and it was suggested to me that I should use

var $j = jQuery.noConflict();

Is there a way I can unsure I don't receive the undefined error when setting my $j variable?

Thanks in advance.

I'm new to jQuery and I'm getting an error in a web page of mine as follows: "Uncaught TypeError: Cannot read property 'noConflict' of undefined"

I'm using jQuery in my page and it was suggested to me that I should use

var $j = jQuery.noConflict();

Is there a way I can unsure I don't receive the undefined error when setting my $j variable?

Thanks in advance.

Share Improve this question edited May 9, 2016 at 15:50 Mike Cluck 32.5k13 gold badges83 silver badges94 bronze badges asked May 9, 2016 at 15:47 RedQueriesRedQueries 1591 gold badge1 silver badge8 bronze badges 3
  • 1 That error has occurred, jquery is not loaded in your html. Add this in your header area <sript src='https://code.jquery./jquery-2.2.3.min.js'> – 0xdw Commented May 9, 2016 at 15:48
  • This mean that jQuery is not loaded in the web page, are you loading it? – Gumma Mocciaro Commented May 9, 2016 at 15:49
  • 2 Something is weird here, because if jQuery were simply not defined, the error would be Uncaught ReferenceError: jQuery is not defined. The error which FRed gets apperas like the jQuery variable is declared but its value is undefined. – CherryDT Commented May 9, 2016 at 15:50
Add a ment  | 

2 Answers 2

Reset to default 3

I Faced the same problem.

Please Use the code like this.

Click Here
(function($) {

    $('#dev').click(function(){
        alert();/*You can add any code here */

    });

    })(jQuery);

If you want to Use .noconflict ment I will edit this.

Assuming you are currently not loaded jQuery into your html page. So your html looks like this after jQuery is loaded.

<!DOCTYPE html>
<html>

  <head>
    <title></title>
    <!-- load jQuery in header area -->
    <script src="https://code.jquery./jquery-2.2.3.min.js"></script>
  </head>

  <body>

    <!-- content -->

    <script>

      var $j = jQuery.noConflict();

      console.log($j); // function (a,b){return new n.fn.init(a,b)}

    </script>
  </body>

</html>
发布评论

评论列表(0)

  1. 暂无评论