# Difficulty with external JS file

**URL:** <https://community.hubspot.com/t/difficulty-with-external-js-file/51698>\
**Category:** CMS Development\
**Tags:** free\
**Created:** [February 16, 2022, 10:41pm UTC](https://community.hubspot.com/t/difficulty-with-external-js-file/51698 "2022-02-16T22:41:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AOjulari](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@AOjulari](https://community.hubspot.com/u/AOjulari)\
**Post date:** [February 16, 2022, 10:41pm UTC](https://community.hubspot.com/t/difficulty-with-external-js-file/51698/1 "2022-02-16T22:41:01Z")

</div>

Hi, I have difficulty to make my function work in module.html(html + hubl). I have external javascipt file and I added the js file to using **Linked Files.**

I am in my module.html (footer), I want to use my function.

This is just an example.

function setText() {

return new Date().getFullYear();

}

In my module.html.

\<p class=“mb-24 md:mb-0 font-display text-16 md:float-left text-paper text-opacity-50”\>© \<Here\>

_**I want to call the function setText()**_

HubSpot. All Rights Reserved.\</p\>

 ![Screen Shot 2022-02-16 at 5.36.43 PM.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/3/374aca64f541ffaf214ad41076006f122bb0a952.png)

I want to use alpine to display it. The entire site has alpine which was used in header.

\<span x-text=“setText()”\>\</span\>

But it is not displaying at all. What Can I do?

---

<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:** [February 17, 2022, 7:54pm UTC](https://community.hubspot.com/t/difficulty-with-external-js-file/51698/2 "2022-02-17T19:54:33Z")

</div>

@AOjulari

Are you still working on this? Do you get any errors? Do you have an example?

---

<div class="post-metadata">

**Author:** ![AOjulari](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@AOjulari](https://community.hubspot.com/u/AOjulari)\
**Post date:** [February 17, 2022, 8:05pm UTC](https://community.hubspot.com/t/difficulty-with-external-js-file/51698/3 "2022-02-17T20:05:14Z")

</div>

Hi, thanks no error but it is not displaying for some reason.

---

<div class="post-metadata">

**Author:** ![lindahl](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lindahl/32/220871_2.png) [@lindahl](https://community.hubspot.com/u/lindahl)\
**Post date:** [February 21, 2022, 6:54am UTC](https://community.hubspot.com/t/difficulty-with-external-js-file/51698/4 "2022-02-21T06:54:11Z")

</div>

Hi @AOjulari ,

I think the problem is in your code. I simplified and code and recommend do this inside module first.

**module.html**

`<p class="mb-24 md:mb-0 font-display text-16 md:float-left text-paper text-opacity-50"><span class="time"></span> All Rights Reserved.</p>`

**module.js**

`document.querySelector(".time").innerHTML = new Date().getFullYear();`

The code above explained I’ve created a scripted that would set the current year then append that value to the span tag with a classname.

The reason why your code doesn’t work is because you need to save your function as a variable and pass it to the HTML, remember, JS is all about client side, so it won’t render as is. If this is a backend language, then it will all makes sense.

Hope that helps 😉

---

<div class="post-metadata">

**Author:** ![AOjulari](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@AOjulari](https://community.hubspot.com/u/AOjulari)\
**Post date:** [February 22, 2022, 8:59pm UTC](https://community.hubspot.com/t/difficulty-with-external-js-file/51698/5 "2022-02-22T20:59:47Z")

</div>

Hi,

`<span x-data="{ settext: setText() }" x-text="settext"></span>`

Thanks! But I was able to solve it by using

Thank you all.

---

<div class="post-metadata">

**Author:** ![lindahl](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lindahl/32/220871_2.png) [@lindahl](https://community.hubspot.com/u/lindahl)\
**Post date:** [February 23, 2022, 5:11am UTC](https://community.hubspot.com/t/difficulty-with-external-js-file/51698/6 "2022-02-23T05:11:56Z")

</div>

Hi @AOjulari , glad you have your solution, sorry didn’t saw that you’re using a JS framework (Alpine).
