$(document).ready(function(){
$(".showhide").click(function(){
$("nav").slideToggle("slow");
});
});
I'm not a JavaScript programmer. I'm getting this error: Uncaught TypeError $ is not a function
For some reason my navigation is not working. Someone told me to put this in JavaScript but I'm getting the error.
Found this: jQuery(document);
but don't know how to use this.
This is how you should do it specially on WordPress (since Wordpress is usually using
jQuery
instead of$
)Reference here
or if you don't like the answer above, you can add
var $ = jQuery;
before the$(document).ready
functionThe issue is that WordPress uses jQuery in compatibility mode, which means that it does NOT utilize the
$
by default.You CAN use the
$
to access jQuery, but you just need to wrap it in a document ready function.Here's the simplest way to do this:
For completeness sake, be sure you have enqueued jQuery.
In your theme's
functions.php
file, or in your plugin's main file, add this:This ensures that jQuery is loaded - the right way - in your WordPress site.
You should use
jQuery
instead of$
if you still gets the error do as following.