- I'm using a WordPress site.
- I'm including this script in the header.
When the script loads, I get this error:
TypeError: 'undefined' is not a function (evaluating '$(document)')
I have no idea what is causing it or what it even means.
In firebug, I get this:
$ is not a function
Also check for including jQuery, followed by some components/other libraries (like jQuery UI) and then accidentially including jQuery again - this will redefine jQuery and drop the component helpers (like .datepicker) off the instance.
I had this problem only on Chrome.
I tried adding
just before calling
It worked.
Thanks a lot
Use this:
Place your js code inside the closure above , it should solve the problem.
Two things:
wrap all the script between this...
Many JavaScript libraries use $ as a function or variable name, just as jQuery does. In jQuery's case, $ is just an alias for jQuery, so all functionality is available without using $. If you need to use another JavaScript library alongside jQuery, return control of $ back to the other library with a call to $.noConflict(). Old references of $ are saved during jQuery initialization; noConflict() simply restores them.