Jump to content

Uncaught ReferenceError: $ is not defined

Recommended Posts

Hi there, 

I was following this a tutorial about adding a page fade-in once the page has loaded. It is set up so it works even if javascript is disabled, which is ideal. https://www.abeautifulsite.net/a-clean-fade-in-effect-for-webpages

However i am trying to add another class the snippet to the script tag that appears immediately after the opening <body> tag: 

<script>document.body.className += ' fade-out'; $(".wrap").addClass(" fade-out");</script>

However I am getting the following error: "Uncaught ReferenceError: $ is not defined". I am assuming this is because I am not calling in jquery in the header? But why then does it work fine without my additional snippet?

Maybe I am taking the wrong approach here, let me know if this could work.


Share this post

Link to post
Share on other sites

You have vanilla JavaScript, and jQuery doing the same in adding a class. The plain JavaScript  will work fine, as it does not need a link to files etc to run, but jQuery does, hence the error

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now