I use the flashcard program Anki to learn Spanish. I am trying to work on some code to look up the allow me to click on the individual words for a definition. I seem to be getting inconsistent results do to returns and formatting included in the text. Any help would be appreciated.
<script>
var content = document.getElementById("Esp Sentence").innerHTML;
var bldRepl = content.replace(/<b>/g,"");
var itlRepl = bldRepl.replace(/<i>/g,"");
var unlRepl = itlRepl.replace(/<u>/g,"");
var divRepl = unlRepl.replace(/<div>/g,"");
var brRepl = divRepl.replace(/<br>/g,"");
var punctuationless = brRepl.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()\?\¿\¡]/g, "");
var mixedCase = punctuationless.replace(/\s{2,}/g, "");
var finalString = mixedCase.toLowerCase();
var words = (finalString).split("");
var punctuatedWords = (brRepl).split("");
var processed = "";
for (i = 0; i < words.length; i++) {
processed += "<a href = \"https://www.spanishdict.com/translate/" + words[i] + "#Spanish\">";
processed += punctuatedWords[i];
processed += "</a> ";
}
document.getElementById("Esp Sentence").innerHTML = processed;
</script>