AJS triggers document.ready before page loaded

Anil Kumar January 14, 2020
AJS.$(document).ready(function() {
console.log(AJS.$("#dialog-show-button").length);
});

displays 0 but it displays 3 when i ran in browser console. Please help me here what it is going wrong?

 

Regards,

Anil

1 comment

DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 14, 2020

@Anil KumarFor Jira, don't use AJS.$(document).ready() and use AJS.toInit()

Your function will look this this,

AJS.toInit(function() {
console.log(AJS.$("#dialog-show-button").length);
});
Anil Kumar January 14, 2020

if i use AJS.toInit() also getting same issue.

DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 15, 2020

Seems like elements are lazy loaded!!

Anil Kumar January 15, 2020

Is there any solution for lazy loaded elements?

DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 15, 2020

You can give AJS.$.live() a trial if that fits your need. Please refer JQuery documentation for details.

https://api.jquery.com/live/

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events