javascript - JQuery - $ is not defined -
i have simple jquery click event
<script type="text/javascript"> $(function() { $('#post').click(function() { alert("test"); }); }); </script>
and jquery reference defined in site.master
<script src="<%=resolveurl("~/scripts/jquery-1.3.2.js")%>" type="text/javascript"></script>
i have checked script being resolved correctly, i'm able see markup , view script directly in firebug, must being found. still getting:
$ not defined
and non of jquery works. i've tried various variations of $(document).ready , jquery etc.
it's mvc 2 app on .net 3.5, i'm sure i'm being dense, everywhere on google says check file reference correctly, have checked , checked again, please advise! :/
that error can caused 1 of 3 things:
- your javascript file not being loaded page
- you have botched version of jquery. happen because edited core file, or plugin may have overwritten $ variable.
- you have javascript running before page loaded, , such, before jquery loaded.
you should check firebug net panel see if file being loaded properly. if not, highlighted red , "404" beside it. if file loading properly, means issue number 2.
make sure jquery javascript code being run inside code block such as:
$(document).ready(function () { //your code here });
this ensure code being loaded after jquery has been initialized.
one final thing check make sure not loading plugins before load jquery. plugins extend "$" object, if load plugin before loading jquery core, you'll error described.
note: if you're loading code not require jquery run not need placed inside jquery ready handler. code may separated using document.readystate
.
Comments
Post a Comment