To add jQuery and JavaScript to your web pages, first add a <script> tag that loads the jQuery library, and then add your own <script> tags with your custom code.
Steve Souders' book High Performance Web Sites recommends putting scripts at the bottom, before the </body> tag.
You need to have a @require
in the user script header to load jQuery. Something like:
// @require http://code.jquery.com/jquery-3.4.1.min.js
(Selecting your desired version from the of list of available versions of jQuery)
For future googlers,
If you have used the above method and still jQuery doesn't seem to be loaded by your script try looking at the spaces, And try to match the indentation with the rest of the header. Apparently the indentation is important.
Faulty:
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://stackoverflow.com/*
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @grant none
// ==/UserScript==
Correct:
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://stackoverflow.com/*
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @grant none
// ==/UserScript==
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With