javascript - jQuery "$ is not a function" error -


i swear have included jquery in page header, right there!

nonetheless following code, i've included near bottom of page (and inline now) gives me error saying "typeerror: $ not function."

<script>         function displayresult(longa, lata, longb, latb, units) {             $("#distance").html(calcdist(longa, lata, longb, latb, units));             if (units=="m") {                 $("#unitlabel").html("miles");                 $("units").prop("selectedindex",0);             } else {                 $("#unitlabel").html("kilometers");                 $("#units").prop("selectedindex",1);             }             $("#longa").val(longa);             $("#lata").val(lata);             $("#longb").val(longb);             $("#latb").val(latb);         }          $("#calculatebutton").click(function() { //this line it's complaining             var longa=$("#longa").val();             var lata=$("#lata").val();             var longb=$("#longb").val();             var latb=$("#latb").val();             var units=$("#units").val();             displayresult(longa, lata, longb, latb, units);         })(jquery);     </script> 

higher in page header i've got following:

<script src="jquery.js" ></script> <script src="calcdistsinglepage.js" ></script> 

i'm not using wordpress or anything, straightforward hand-coded html page.

try wrapping code in closure (which considered practice anyways):

(function($) {     $("#calculatebutton").click(function() {       // stuff...     }); }(jquery)); 

if snippet still complains same error, there's bound problem way you're loading jquery library.

also, make sure don't overwrite $ variable in other code. example, inside calcdistsinglepage.js.

the dollar-sign straight-forward javascript variable , can reassigned whatever want. according error, $ something not function (otherwise you'd receive referenceerror stating $ undefined). probably, somewhere in code, you've overwritten it.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -