Uncaught Typeerror: $ Is Not a Function

The dollar-sign ($) in Javascript has for many years now been associated with jQuery.

When you see this error:

“uncaught typeerror: $ is not a function

It almost always means that a jQuery piece of code is being run before the jQuery library has been initialised and loaded.

Oftentimes, your code will wait for jQuery to load before continuing any processing, this is almost always done as follows:

    // jQuery code is in here

However, it’s not uncommon to get an “TypeError: $ is not a function ” error in response.

Some developers resolve this by wrapping their code as follows:

    // jQuery code is in here

What this does is, it forces a scoped jQuery variable to be re-aliased within an anonymous function in your application.

Alternatively, you can just do the following:

  //you can now use $ as your jQuery object.
  var body = $( 'body' );