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:

  1. your javascript file not being loaded page
  2. you have botched version of jquery. happen because edited core file, or plugin may have overwritten $ variable.
  3. 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

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -