How to user jQuery from a greasemonkey script?

Hi there

I'm trying to create a greasemonkey script to tweak the Jira UI. I want to use jQuery but when I do I get:{code}

Uncaught ReferenceError: $ is not defined


So I change it to reference AJS and get:


Uncaught ReferenceError: AJS is not defined


The script is pretty simple so far:


document.body.onload = function(){





Any ideas?


2 answers


Per this other answers post, it sounds like the AtlassianUI pieces aren't loading correctly. Are you able to get this working via a local (development) copy of JIRA as would be generated by the Plugin SDK? If you can get it working correctly against a download copy of JIRA, then perhaps you can get it working against OnDemand with a bit of tweaking?

Does that help?

Sorry Tyler, don't have the time to download, install, configure & debug a local version. Given that we're just using the default OnDemand instance I guess it shouldn't be hard for you to repro?

Hey Richard,

So content scripts run in an isolated environment:

Which essentially means you can't access the jquery/existing javascript without a little work.

So to access the existing jquery in the page you have several methods. Chrome doesn't support @require so you can't use that to reference the jquery.js if using chrome. Best way is prob to inject :

function scriptLoader(callback) {

var script = document.createElement("script");

script.textContent = "(" + callback.toString() + ")();";



function mainCode() {



I probably should have said - this isn't a JIRA specific issue its just the way userscripts interact with the browser.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,804 views 18 22
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you