# Broken JavaScriptafter updating

**URL:** <https://forums.ankiweb.net/t/broken-javascriptafter-updating/39809>\
**Category:** Card Design\
**Created:** [January 16, 2024, 4:20am UTC](https://forums.ankiweb.net/t/broken-javascriptafter-updating/39809 "2024-01-16T04:20:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ken](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Ken](https://forums.ankiweb.net/u/Ken)\
**Post date:** [January 16, 2024, 4:20am UTC](https://forums.ankiweb.net/t/broken-javascriptafter-updating/39809/1 "2024-01-16T04:20:22Z")

</div>

Hello, the JavaScript on my template breaks after updating. To demonstrate what I mean, we can use the **Basic** card type with a simplified version of what I am experiencing. The card can have anything on the front and the back.

The following is the back template.

```auto
<span id="abcd">
{{FrontSide}}
<hr id=answer>

{{Back}}
<span id="abcd">
<script>
document.getElementById("abcd").innerHTML = "";
</script>

```

As you can see, document.getElementById(“abcd”).innerHTML = “” should replace the whole back template with “” and that is exactly what it does.  
However, my problem comes when you try to add almost anything else. Let’s just add 2 more lines.

```auto
<span id="abcd">
{{FrontSide}}
<hr id=answer>

{{Back}}
<span id="abcd">
<script>
const HIRAGANA_START = 0x3041;
const HIRAGANA_END = 0x3096;
document.getElementById("abcd").innerHTML = "";
</script>

```

Now, the JavaScript is completely broken and the whole black template is **not** replaced with “”. I was previously using 2.1.35 and I updated to use

```auto
Version <U+2068>23.12.1 (1a1d4d54)<U+2069>
Python 3.9.15 Qt 6.6.1 PyQt 6.6.1

```

What is the problem here?

---

<div class="post-metadata">

**Author:** ![jcznk](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/jcznk/32/15215_2.png) [@jcznk](https://forums.ankiweb.net/u/jcznk)\
**Post date:** [January 16, 2024, 4:55am UTC](https://forums.ankiweb.net/t/broken-javascriptafter-updating/39809/2 "2024-01-16T04:55:55Z")

</div>

Maybe try checking this:

> [@How to put a random field inside a div with a script?](https://forums.ankiweb.net/t/how-to-put-a-random-field-inside-a-div-with-a-script/21508/9):
>
> The issue is the const keyword. Because the document persists between cards, using const outside of functions (outermost scope) causes a SyntaxError. Use the keyword var instead or enclose the script in an IIFE, like: (() =\> { const fields = document.querySelectorAll(".sentence"); fields[3].hidden = false; })();

---

<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:** [February 15, 2024, 4:56am UTC](https://forums.ankiweb.net/t/broken-javascriptafter-updating/39809/3 "2024-02-15T04:56:21Z")

</div>

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