# JavaScript not working for Version ⁨24.11

**URL:** <https://forums.ankiweb.net/t/javascript-not-working-for-version-24-11/55508>\
**Category:** Card Design\
**Created:** [February 7, 2025, 10:32am UTC](https://forums.ankiweb.net/t/javascript-not-working-for-version-24-11/55508 "2025-02-07T10:32:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yunakam](https://avatars.discourse-cdn.com/v4/letter/y/9f8e36/32.png) [@yunakam](https://forums.ankiweb.net/u/yunakam)\
**Post date:** [February 7, 2025, 10:32am UTC](https://forums.ankiweb.net/t/javascript-not-working-for-version-24-11/55508/1 "2025-02-07T10:32:12Z")

</div>

I just installed the latest version of Anki, and want to integrate JavaScript code for a card template.  
I tested with the following simple test code in Front Template for one of my cards:

```auto
<div>
    {{Front}}
    <p id="test">Text</p>
    <script>
        document.addEventListener("DOMContentLoaded", function() {
            document.getElementById("test").innerText = "JavaScript is working";
        });
    </script>
</div>

```

and see that JavaScript is _not_ working as it shows the content of {{Front}} and the text “Text”, but not “JavaScript is working” in Preview.

Is there anything to be done to start with JavaScript on Anki?  
Sorry for such a basic question, but I couldn’t find a post asking the same.

Version ⁨24.11 (87ccd24e)⁩  
Python 3.9.18 Qt 6.6.2 PyQt 6.6.1

---

<div class="post-metadata">

**Author:** ![Anon\_0000](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@Anon\_0000](https://forums.ankiweb.net/u/Anon_0000)\
**Post date:** [February 7, 2025, 10:54am UTC](https://forums.ankiweb.net/t/javascript-not-working-for-version-24-11/55508/2 "2025-02-07T10:54:32Z")

</div>

Probably because of this (quote by @hkr):

> You can’t use window.onload or window.addEventListener(‘DOMContentLoaded’, …), because Anki desktop only updates a part of the DOM tree when displaying a card rather than refreshing the whole page.

> [@This piece of javascript does not seem to work (hint button)](https://forums.ankiweb.net/t/this-piece-of-javascript-does-not-seem-to-work-hint-button/9627/4):
>
> (Disclaimer: I’m just a user of Anki.) First of all, Javascript feature in Anki is only intended for advanced users, and is not officially guaranteed to work. See [here](https://docs.ankiweb.net/#/templates/styling?id=javascript). Secondly, you can use Google Chrome to debug the webview of the card screen. Desktop [Introduction - Writing Anki Add-ons](https://addon-docs.ankiweb.net/#/porting2.0?id=webview-changes) You can now debug the webviews using an external Chrome instance, by setting the env var QTWEBENGINE\_REMOTE\_DEBUGGING to 8080 prior to starting Anki, then surfing to localhost:8080 in Chrome. AnkiD…

(to clarify: js does work if you use things that are supported. I have custom card templates that use a lot of js and it works fine, same for a bunch of other users here)

---

<div class="post-metadata">

**Author:** ![yunakam](https://avatars.discourse-cdn.com/v4/letter/y/9f8e36/32.png) [@yunakam](https://forums.ankiweb.net/u/yunakam)\
**Post date:** [February 8, 2025, 1:10am UTC](https://forums.ankiweb.net/t/javascript-not-working-for-version-24-11/55508/3 "2025-02-08T01:10:27Z")

</div>

That was exactly it. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [March 10, 2025, 1:11am UTC](https://forums.ankiweb.net/t/javascript-not-working-for-version-24-11/55508/4 "2025-03-10T01:11:13Z")

</div>

Closed on March 10, 2025, 1:11am UTC

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