# Fetch partial in javascript

**URL:** <https://discourse.gohugo.io/t/fetch-partial-in-javascript/38647>\
**Category:** support\
**Created:** [May 16, 2022, 5:05pm UTC](https://discourse.gohugo.io/t/fetch-partial-in-javascript/38647 "2022-05-16T17:05:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tut](https://avatars.discourse-cdn.com/v4/letter/t/e95f7d/32.png) [@tut](https://discourse.gohugo.io/u/tut)\
**Post date:** [May 16, 2022, 5:05pm UTC](https://discourse.gohugo.io/t/fetch-partial-in-javascript/38647/1 "2022-05-16T17:05:08Z")

</div>

How do I fetch a partial inside the JS in the code below where it says “partial goes here”? The partial has HTML and Hugo syntax in it. I am using the code in single.html file

```auto
<button id="drop" class="drop">Toggle Comments</button>
      <article class="comment" id="comment">
   <!-- partial content goes here -->
      </article>
      <script type="text/javascript">
          document.querySelector('#drop').addEventListener('click', 
  () => fetch('PARTIAL GOES HERE')
    .then(res => res.text())
    .then(data => document.querySelector('#comment').innerHTML = data))
      </script>

```

(Is this really possible? Or it is a server-side thing?)

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [May 16, 2022, 5:14pm UTC](https://discourse.gohugo.io/t/fetch-partial-in-javascript/38647/2 "2022-05-16T17:14:36Z")

</div>

> [@tut](#):
>
> (Is this really possible? Or it is a server-side thing?)

It’s possible, but I’m not sure I would want to do it. I Probably would go the JSON route. But whatever you want to `fetch` ned to be available as an URL. One simple route to this is to put it (or mount it) inside /static.

---

<div class="post-metadata">

**Author:** ![chrillek](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/chrillek/32/19797_2.png) [@chrillek](https://discourse.gohugo.io/u/chrillek)\
**Post date:** [May 17, 2022, 12:28pm UTC](https://discourse.gohugo.io/t/fetch-partial-in-javascript/38647/4 "2022-05-17T12:28:55Z")

</div>

And _how_ do you fetch it, with which URL?

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [May 27, 2022, 3:19pm UTC](https://discourse.gohugo.io/t/fetch-partial-in-javascript/38647/5 "2022-05-27T15:19:09Z")

</div>

Closed on May 27, 2022, 3:19pm UTC

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
