Confused jQuery not found when I know it

I made sure my jQuery reference is correct.

window.onload = function() {
  console.log($(this));
};

I get to see a nonzero value. But when I try to execute any of the following (commented on the part above), I get an error message.

Unprepared ReferenceError: $ undefined

//$(document).ready(function () { alert("ready"); });
$(window).onload(function () { alert("onload"); });

I am confused by how it can be defined and not defined at the same time. After some googling, I found some code examples like this , and as far as I can tell, this is not the syntax in the file.

The markup looks like this.

<head>
  ...
  <script src="Stuff.js" type="text/javascript"></script>
</head>
<body>
  ...
  @Scripts.Render("~/bundles/jquery")
</body>

( ) MVC.NET Razor, @Scripts.Render("~/bundles/modernizr") , @Scripts.Render("~/bundles/jquery") . , . , . . - .

0
1

script jQuery . script , , .

, , undefined , . $ :

:

window.onload = function() {
  console.log($(this));
};

, HTML, script , .., load window - .

:

//$(document).ready(function () { alert("ready"); });
$(window).onload(function () { alert("onload"); });

, script, , JavaScript, JavaScript .

, :

<script>
window.onload = function() {
    console.log($(this));
};
</script>
<script src="jquery.js"></script>

:

<script>
$(document).ready(funtion() {
    alert("ready");
});
</script>
<script src="jquery.js"></script>

:

<script src="jquery.js"></script>
<script>
$(document).ready(funtion() {
    alert("ready");
});
</script>
+3

Source: https://habr.com/ru/post/1622761/


All Articles