How to use jQuery in Sage 10.2.0

Hello!
I’m using Sage 10 for the very firt time and I really need to use jQuery, but I’m having a hard time trying to use $. It keeps throwing the error

app.js:75 Uncaught (in promise) TypeError: $ is not a function

I’m using

.provide({
      jquery: ["jQuery", "$"],
 })

But it doesn’t seem to work. The only way I found to make it work is inside the function

jQuery(function($) {}

but it doesn’t seems the best solution… :face_with_raised_eyebrow:

Any ideas of what I’m doing wrong?
Thank you!

Howdy! If you’re using jQuery from WordPress core, I believe that it’s expected behavior for only jQuery to work and not $

It seems fine to me, but the best solution is to avoid jQuery at this point. Even if you’ve got other plugins that are adding it as a dep, do you really need to use it yourself? But anyway, if that you’ve got is able to execute as expected, then I’d roll with it!

Thank you for your reply!
I’m trying my best avoiding jQuery so far. I need to do some animation, I never used React :person_gesturing_ok: :woman_facepalming: and I have no time learning for this project.
Anyway, if I really need jQuery I will use it as it is!

Thank you very much :slight_smile:

You’re welcome!

I wouldn’t suggest replacing jQuery with React, but instead give vanilla JS a shot for most things. Also, take a look at Alpine.js at some point!

1 Like

Here is a good resource for replacing a lot of what jQuery offers with plain 'ol javascript https://youmightnotneedjquery.com/

2 Likes

Thank you for you sugestion, for the next projects I’ll strongly consider using React. For now maybe I’ll stay with vanilla, I guess Green Sock uses vanilla, so I’m safe.

Thank you very much, it will be really usefull!!!