AFetter AFetter - 5 months ago 10x
Javascript Question

jquery document ready return null but the console are able to get value

I'm working in a solution inside a CMS (EPiServer).

If I use the console.log to check my object I get a null value.

$(document).ready(function () {
console.log("$('.EPiRequester').html() =" + $('.EPiRequester').html());

(function myLoop(i) {
setTimeout(function () {
console.log(i + $('.EPiRequester').html());
if (--i) myLoop(i);
}, 3000)

10 times return null as well.

but if I right in the console to check, the html() method return a value.

"EPi Requester"

any idea about this problem?


To fix this issue, I changed my method to open the Dialog box. Opening a Dialog with a Iframe I'm able to run all javascript and jQuery.

I didn't understand what was the problem.

function openModalFromIframe(that) {
    require(["epi/shell/widget/dialog/Dialog"], function (Dialog) {

        var url = $(that).attr('data-iframe-url');
        var title = $(that).attr('data-title');

        var dialog = new Dialog({
            Title: title,
            loadingMessage: "Loading...",
            defaultActionsVisible: false,
            preventCache: true,
            style: "width: 800px; ",
        dialog.attr("content", '<iframe src="' + url + '" style=" width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden;"></iframe>');;

If someone get the same issue here are my workaround.