JavaScript to replace text string with image?


Is it possible to add a script to the card template that replaces every instance of a specific text string with a matching image previously saved to the Anki folder?

Example: every instance of the text “one” in these cards are replaced with the image _one.png from the media folder when reviewing.

Could something like this be made to work?

<div id=front />
var str = document.getElementById("Front").innerHTML;
var res = str.replace(/one/g, "<img src='_one.png'>");
document.getElementById("Front").innerHTML = res;
<div id=front>{{Front}}</div>

var str = document.getElementById("front").innerHTML;
var res = str.replace(/one/g, "<img src='_one.png'>");
document.getElementById("front").innerHTML = res;
1 Like

Thank you :pray:

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