# Javascript code doesn't applied on all notes

**URL:** <https://forums.ankiweb.net/t/javascript-code-doesnt-applied-on-all-notes/37951>\
**Category:** Card Design\
**Created:** [December 3, 2023, 11:00am UTC](https://forums.ankiweb.net/t/javascript-code-doesnt-applied-on-all-notes/37951 "2023-12-03T11:00:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![azertyboy](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@azertyboy](https://forums.ankiweb.net/u/azertyboy)\
**Post date:** [December 3, 2023, 11:00am UTC](https://forums.ankiweb.net/t/javascript-code-doesnt-applied-on-all-notes/37951/1 "2023-12-03T11:00:32Z")

</div>

Hello,

I created my custom card type with little javascript code inside.

Firstly I created without javascript then I edited javascript after studied some cards.

The javascript code is not applied on some notes when I review them.

I read in the Anki’s documentation (Javascript section) that the cards have some parts re-generated on review.  
So I think my javascript code is not applied when I review already studied cards.

Anyone can help me about that ?  
Can we force to regenerate all cards on review ?

Best regards.

* * *

**Anki version :**  
Version ⁨2.1.66 (70506aeb)⁩  
Python 3.9.15 Qt 6.5.2 PyQt 6.5.2

**Platform :** Windows 11

**javascript code :**

```auto
const pronunciationEl = document.getElementById('pronunciation');
const pronunContent = pronunciationEl.innerText.trim();
if (pronunContent.length == 0) {
	pronunciationEl.style.display = 'none';
}

```

---

<div class="post-metadata">

**Author:** ![abdo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/abdo/32/654_2.png) [@abdo](https://forums.ankiweb.net/u/abdo)\
**Post date:** [December 3, 2023, 10:41pm UTC](https://forums.ankiweb.net/t/javascript-code-doesnt-applied-on-all-notes/37951/2 "2023-12-03T22:41:36Z")

</div>

Try wrapping the code in a function:

```javascript
(() => {
	const pronunciationEl = document.getElementById('pronunciation');
	const pronunContent = pronunciationEl.innerText.trim();
	if (pronunContent.length == 0) {
		pronunciationEl.style.display = 'none';
	}
})();

```

See: [Do javascript for loops work in html templates? - #5 by hkr](https://forums.ankiweb.net/t/do-javascript-for-loops-work-in-html-templates/28698/5)

---

<div class="post-metadata">

**Author:** ![azertyboy](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@azertyboy](https://forums.ankiweb.net/u/azertyboy)\
**Post date:** [December 4, 2023, 3:30pm UTC](https://forums.ankiweb.net/t/javascript-code-doesnt-applied-on-all-notes/37951/3 "2023-12-04T15:30:50Z")

</div>

Firstly, thanks for your proposal. I will try and say you tomorrow if that works.

Secondly, I found a built-in feature in Anki that does what I want but anyway my topic continue to be interesting.

Thanks. I’ll reply tomorrow.

---

<div class="post-metadata">

**Author:** ![azertyboy](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@azertyboy](https://forums.ankiweb.net/u/azertyboy)\
**Post date:** [December 5, 2023, 7:32am UTC](https://forums.ankiweb.net/t/javascript-code-doesnt-applied-on-all-notes/37951/4 "2023-12-05T07:32:39Z")

</div>

Hello.

That works very well.

Thanks for sharing me the tip.

Best regards.

---

<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:** [January 4, 2024, 7:32am UTC](https://forums.ankiweb.net/t/javascript-code-doesnt-applied-on-all-notes/37951/5 "2024-01-04T07:32:39Z")

</div>

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