Issue with Javascript Code into page builder

Hi, I have an issue with a little piece of code only in page builder ( everything works fine on the “live” version of the pages"

I would like to add a page loader, which disappears when the page is loaded, pretty simple feature .. But when i’m in page builder, ( i guess ) the scipt is not executed, so the loader doesn’t disappear

$('body').append('<div style="" id="loadingDiv"><div class="loader">Loading...</div></div>');
$(window).on('load', function(){
 setTimeout(removeLoader, 2000); //wait for page load PLUS two seconds.
});
function removeLoader(){
 $( "#loadingDiv" ).fadeOut(500, function() {
 // fadeOut complete. Remove the loading div
 $( "#loadingDiv" ).remove(); //makes page more lightweight 
 }); 
}

I have tried to hide it when when the body tag of the page has class .page-editor, but without success

Does anyone have an idea ?

Thanks :slightly_smiling_face:

@stefen , any words of advice here?

@ABrunot @dennisedson I would wrap your script in an if statement like this:

if( window.hsInEditor ) {
 // do nothing if in the HubSpot page editor
 return;
} else {
 // put your scripts here
}

It works, awesome ! I just had to remove the “return;” but it works . Thanks you :slightly_smiling_face: .