# Hide poll result from anonymous

**URL:** https://meta.discourse.org/t/hide-poll-result-from-anonymous/304030
**Category:** Development
**Tags:** polls
**Created:** [April 16, 2024, 5:06am UTC](https://meta.discourse.org/t/hide-poll-result-from-anonymous/304030 "2024-04-16T05:06:52Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![John\_Vawn](https://avatars.discourse-cdn.com/v4/letter/j/8e8cbc/32.png) [@John\_Vawn](https://meta.discourse.org/u/John_Vawn)
#### Post date: [April 16, 2024, 5:06am UTC](https://meta.discourse.org/t/hide-poll-result-from-anonymous/304030/1 "2024-04-16T05:06:53Z")

</div>

Hi, is there a way to hide poll result from anonymous? I’m creating a forum about exam question solving which allow user to choose an answer for question. I don’t need my members to give false answer just to see others’ answers, but I want to prevent anonymous from seeing it too.

---

<div class="post-metadata">

### Author: ![John\_Vawn](https://avatars.discourse-cdn.com/v4/letter/j/8e8cbc/32.png) [@John\_Vawn](https://meta.discourse.org/u/John_Vawn)
#### Post date: [April 16, 2024, 8:06am UTC](https://meta.discourse.org/t/hide-poll-result-from-anonymous/304030/2 "2024-04-16T08:06:36Z")

</div>

One more thing, I try to find a way to hide reply from anonymous too but found nothing. Does such function exist?

---

<div class="post-metadata">

### Author: ![John\_Vawn](https://avatars.discourse-cdn.com/v4/letter/j/8e8cbc/32.png) [@John\_Vawn](https://meta.discourse.org/u/John_Vawn)
#### Post date: [April 16, 2024, 12:34pm UTC](https://meta.discourse.org/t/hide-poll-result-from-anonymous/304030/3 "2024-04-16T12:34:34Z")

</div>

Hi, I just figured it out. If anyone want to try, you can create a theme component and add this to head

```plaintext
<script type="text/discourse-plugin" version="0.8">api.onPageChange(() => {
        if (!Discourse.User.current()) {
            const pollContainers = document.querySelectorAll('.poll');

            pollContainers.forEach(poll => {
                const observer = new MutationObserver((mutations) => {
                    mutations.forEach((mutation) => {
                        if (mutation.type === 'childList') {
                            const resultsButton = poll.querySelector('.toggle-results');
                            if (resultsButton) {
                                resultsButton.remove();
                            }
                        }
                    });
                });

                observer.observe(poll, { attributes: false, childList: true, subtree: true });

                // Remove existing buttons if present
                const existingButton = poll.querySelector('.toggle-results');
                if (existingButton) {
                    existingButton.remove();
                }
            });
        }
    });
</script>

```

This will even prevent the “Results” button to show up when someone votes.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [May 16, 2024, 12:34pm UTC](https://meta.discourse.org/t/hide-poll-result-from-anonymous/304030/4 "2024-05-16T12:34:57Z")

</div>

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