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..