I have a file- “Site.js” with the following method:
function Init() {
$(document).ready(function() {
//some init actions here
});
}
function jQuery.fn.DivToggle(div) {
$(div).toggle('fast');
//some other animation code here
}
in my Index.cshtml file (I’m using asp.net mvc), I have this:
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Site.js")" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
$(function () {
Init();
});
</script>
</body>
</html>
I get this error when I run the project:
“Microsoft JScript runtime error: ‘Init’ is undefined”
Any idea what I’m doing wrong?
Initis not defined because there is a syntax error inSite.js.You can’t actually do that. It should be:
P.S.
$(function(){is the same as$(document).ready(function(){. You don’t need the$(document).ready(function(){inside yourInitfunction.