Jump to content
ben03

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.

Thanks

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...