The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Atlassian JavaScript Code does not work as expected

Albert Cameron
August 15, 2021
AJS.toInit(function () {

$(document).ready(function(){
console.log("loaded");
var button = document.querySelector('#my-button-id');

console.log(button)

var key = AJS.$("#key-val").text();
var url = "/rest/api/1.0/message/"+key

});

 For some reason this javascript Code is always loaded way before the document is fully ready. In my case button is mostly null. Even I use $ (document) . ready function. I have no idea why this is the case..

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
August 15, 2021

You have added this into the wrong place in the .js load.  When a page loads, it executes all the javascript that says it should run duting load, and the stuff you have is not appropriate when it happens.

I would very very very strongly recommend that you stop wedging js into the wrong places.  If you really do want to run js in places, do it with an app, not a bodge into the screen.

Albert Cameron
August 15, 2021
$(document).ready(function() 

is jquery and should prevent loading my code before the page is fully loaded. 

(Right now my code is part of a plugin)

Where should I put my code instead ? Have you got a link ? 

I also found this Extending inline edit for JIRA plugins (atlassian.com) 

By the way we do not use Jira cloud so far.

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
August 16, 2021

Ok, so it's in the wrong place in your app.  I can't tell you any more than the doc you've found does.