Text on card overwritten by javascript

I’m not sure if this is the right section for this, but I’ll try here anyways.

I’ve been trying to get javascript to work in my cards, and now that it finally works, the javascript overwrites the text, and formatting already on the card.
What could I do to solve this?


Do you actually need javascript to put text on your cards? Javascript in Anki is best for processing text, not showing text. Whatever you are trying to accomplish, just do it without document.write(). Or use that function for debugging only and then delete it.

Well I’m trying to generate random numbers, to make unique maths problems each time I come across a card. Would I still be able to do this?

Probably. You can use javascript to generate the number but just use html to display it.

I can’t help you with the JS, but I will offer you an idea to consider. Randomly generated cards are not great for spaced repetition. With “practice”-type cards, you’re generally not trying to memorize the substance of the card – which is what Anki (or any other SRS) is designed to do.

If you get a card wrong, and grade your answer Again – the card that comes up after a few minutes in Relearn won’t be the same. So you don’t get to see the card that you missed, and you’re spending time on a card you might not even need to study. If you get your card right – the card that comes up after a few days or weeks in Review won’t be the same either. How you did on one practice problem doesn’t necessarily bear on how much you need to study other similar problems. And your review history for each card will be meaningless.

1 Like

Most of the time, it’s not a good idea to do this. But, sometimes you may want to ask different questions that test you on the same piece of knowledge. Emphasis on same.

If you don’t mind writing the cards yourself, you can use the templates here: Interactive_And_Randomize_Anki_Note_Types/Match Pairs and Randomized Cloze.apkg at main · Vilhelm-Ian/Interactive_And_Randomize_Anki_Note_Types · GitHub

You’ll need to put the content separated by a pipe (|) and the JS will randomly pick one and show it in the card.