# Script is not working on publish

**URL:** <https://community.hubspot.com/t/script-is-not-working-on-publish/95797>\
**Category:** CMS Development\
**Tags:** javascript\
**Created:** [December 11, 2023, 3:31pm UTC](https://community.hubspot.com/t/script-is-not-working-on-publish/95797 "2023-12-11T15:31:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![AKilinctekin](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@AKilinctekin](https://community.hubspot.com/u/AKilinctekin)\
**Post date:** [December 11, 2023, 3:31pm UTC](https://community.hubspot.com/t/script-is-not-working-on-publish/95797/1 "2023-12-11T15:31:47Z")

</div>

Hello,  
I am trying to embed a script inside a cloned module’s, which name is post filter, hubl codes . When in edit mode, I preview the page and I see the script is working but when I publish the page, the script is not working on published page. What can I do to make this work?

---

<div class="post-metadata">

**Author:** ![jnix284](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jnix284/32/29_2.png) [@jnix284](https://community.hubspot.com/u/jnix284)\
**Post date:** [December 11, 2023, 3:42pm UTC](https://community.hubspot.com/t/script-is-not-working-on-publish/95797/2 "2023-12-11T15:42:38Z")

</div>

[@AKılınçtekin](https://community.hubspot.com/t5/user/viewprofilepage/user-id/677231) did you replace the module on the page with the new cloned module that has the script?

If it’s still the original module before you added the script, it won’t update on the page.

---

<div class="post-metadata">

**Author:** ![AKilinctekin](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@AKilinctekin](https://community.hubspot.com/u/AKilinctekin)\
**Post date:** [December 11, 2023, 5:40pm UTC](https://community.hubspot.com/t/script-is-not-working-on-publish/95797/3 "2023-12-11T17:40:48Z")

</div>

Yes, I replaced the module. I see the changes on the preview actually. But as I said before, I cannot see the changes on the published page.

---

<div class="post-metadata">

**Author:** ![jnix284](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jnix284/32/29_2.png) [@jnix284](https://community.hubspot.com/u/jnix284)\
**Post date:** [December 11, 2023, 6:48pm UTC](https://community.hubspot.com/t/script-is-not-working-on-publish/95797/4 "2023-12-11T18:48:50Z")

</div>

[@AKılınçtekin](https://community.hubspot.com/t5/user/viewprofilepage/user-id/677231) can you share more about what the script is supposed to do?

page link? script name JS name?

---

<div class="post-metadata">

**Author:** ![AKilinctekin](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@AKilinctekin](https://community.hubspot.com/u/AKilinctekin)\
**Post date:** [December 11, 2023, 8:43pm UTC](https://community.hubspot.com/t/script-is-not-working-on-publish/95797/5 "2023-12-11T20:43:20Z")

</div>

{# Module variables #}

{% if module.select\_blog is number %}  
{% set select\_blog = module.select\_blog %}  
{% else %}  
{% set select\_blog = “default” %}  
{% endif %}

{% if module.show\_all\_filters == true %}  
{% set max\_link\_param = “” %}  
{% else %}  
{% set max\_link\_param = module.max\_links %}  
{% endif %}

{# Module content #}

{% post\_filter  
select\_blog=“{{ select\_blog }}”,  
expand\_link\_text=“{{ module.expand\_link\_text }}”,  
list\_title=“{{ module.list\_title }}”,  
filter\_type=“{{ module.filter\_type }}”,  
order\_by=“{{ module.order\_by }}”,  
max\_links={{ max\_link\_param }}  
%}

\<script\>  
document.addEventListener(‘DOMContentLoaded’, () =\> {  
const links = document.querySelectorAll(‘.filter-link-count’)  
links.forEach((link) =\> {  
if(link.textContent \<= 15) {  
link.parentNode.parentNode.remove()  
}  
})  
})  
\</script\>  
Here is my script. There are too many -more than 300- links on the page. So that I wanted to remove some \<li\> elements. Normally scripts should do its job.

---

<div class="post-metadata">

**Author:** ![jnix284](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jnix284/32/29_2.png) [@jnix284](https://community.hubspot.com/u/jnix284)\
**Post date:** [December 11, 2023, 9:00pm UTC](https://community.hubspot.com/t/script-is-not-working-on-publish/95797/6 "2023-12-11T21:00:19Z")

</div>

Thanks [@AKılınçtekin](https://community.hubspot.com/t5/user/viewprofilepage/user-id/677231), without seeing the live page to check the deve console for errors, I can’t tell why the script isn’t working.

Maybe @Anton can offer further feedback on the code directly.

---

<div class="post-metadata">

**Author:** ![AKilinctekin](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@AKilinctekin](https://community.hubspot.com/u/AKilinctekin)\
**Post date:** [December 12, 2023, 2:16pm UTC](https://community.hubspot.com/t/script-is-not-working-on-publish/95797/7 "2023-12-12T14:16:40Z")

</div>

Sorry for my late response, here is the live page: [AWS re:Invent 2023 Highlights and Key Takeaways](https://www.kloia.com/blog/reinvent-2023-recap)

---

<div class="post-metadata">

**Author:** ![jnix284](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jnix284/32/29_2.png) [@jnix284](https://community.hubspot.com/u/jnix284)\
**Post date:** [December 15, 2023, 1:43am UTC](https://community.hubspot.com/t/script-is-not-working-on-publish/95797/8 "2023-12-15T01:43:03Z")

</div>

[@AKılınçtekin](https://community.hubspot.com/t5/user/viewprofilepage/user-id/677231) here’s the error:

 ![Jnix284_0-1702604558350.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/0/02308b7cc19392b2b126649726f6e641bcd6c0bf.png)
