Uncaught ReferenceError: jQuery is not defined – although jQuery is loaded [closed]

The error is self-explanatory. When you insert your code, jQuery has not been defined. You have to put that script after jQuery is loaded.

If you can’t change where jQuery is defined, as you say in your comment to Pat J’s answer, then insert your script in the <footer>.