# Issue with Javascript Code into page builder

**URL:** <https://community.hubspot.com/t/issue-with-javascript-code-into-page-builder/37498>\
**Category:** CMS Development\
**Tags:** javascript, html, professional\
**Created:** [May 18, 2021, 12:10pm UTC](https://community.hubspot.com/t/issue-with-javascript-code-into-page-builder/37498 "2021-05-18T12:10:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ABrunot](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/abrunot/32/5125_2.png) [@ABrunot](https://community.hubspot.com/u/ABrunot)\
**Post date:** [May 18, 2021, 12:10pm UTC](https://community.hubspot.com/t/issue-with-javascript-code-into-page-builder/37498/1 "2021-05-18T12:10:45Z")

</div>

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

```lia-code-sample
$('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 🙂

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [May 18, 2021, 6:15pm UTC](https://community.hubspot.com/t/issue-with-javascript-code-into-page-builder/37498/2 "2021-05-18T18:15:28Z")

</div>

@stefen , any words of advice here?

---

<div class="post-metadata">

**Author:** ![stefen](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/stefen/32/29274_2.png) [@stefen](https://community.hubspot.com/u/stefen)\
**Post date:** [May 18, 2021, 11:58pm UTC](https://community.hubspot.com/t/issue-with-javascript-code-into-page-builder/37498/3 "2021-05-18T23:58:54Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![ABrunot](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/abrunot/32/5125_2.png) [@ABrunot](https://community.hubspot.com/u/ABrunot)\
**Post date:** [May 19, 2021, 11:01am UTC](https://community.hubspot.com/t/issue-with-javascript-code-into-page-builder/37498/4 "2021-05-19T11:01:53Z")

</div>

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