How to retrieve the "id" attribute of `<input>` element in front template of Anki from back template

74 views Asked by At

Recently, I've been creating Anki cards with Javascript on card editor. Today, I have a question for you about how do I retrieve the id attribute of <input> element in front template from back template, when cards are flipped to the back side from the front side.

First of all, please confirm the code below.

Front Template

<p>652 - 558</p>
<input type="text" id="answer">

Back Template

<div class="answer-display-area">//Answer will be displayed here.<div>
<script>
const answer = getElementById("answer");
const displayArea = getElementByClassName("answer-display-area");

if(answer.value === "94"){
const pElement =  document.displayArea.appendChild(document.createElement("p"));
pElement.innerHTML = `<p>652−558</p><p style="background-color:#77fc03;">${answer}</p>`;
} else {
const pElement = document.displayArea.appendChild(document.createElement("p"));
pElement.innerHTML = `<p>652−558</p><p style="background-color:red;">${answer}</p>`;

const correctAnswer = "<p>Answer: 94</p>";
const explaination = "<p>Answer is 94.  Please refer to 5th page.Carry down 1 from the ten's place because of the one's place can't subtract 8 from 2.</p>";
displayArea.parentNode.insertBefore(correctAnswer, displayArea);
displayArea.parentNode.insertBefore(explaination, displayArea);
}
</script>

After retrieved the id attribute, I'm planning to obtain value with getElementById("answer");in Javascript code when cards are reverse back side from front side.

0

There are 0 answers