It is probably possible, maybe with some regex, but it would require quite a more complex solution I’m afraid.
Maybe you could try the following workaround:
Front template:
{{Front}}
<div id="type">{{type:Back}}</div>
<div id="back" hidden>{{Back}}</div>
<script>
var typeElement = document.querySelector("#type");
var backElement = document.querySelector("#back");
var backContent = backElement.innerHTML;
var regex = /\btype_answer\b/;
if (!regex.test(backContent)) {
typeElement.style.display = "none";
}
</script>
<script>
(() => {
/**
* Type-in-the-answer live feedback for Anki (vague variant)
* @author Matthias Metelka | @kleinerpirat
*/
const input = document.querySelector("#typeans");
const answer = document.querySelector('.type_answer').innerText;
if (input) {
input.addEventListener("input", () => {
input.classList.add("typed");
input.classList.toggle(
"goodsofar",
input.value == answer.substring(0, input.value.length)
);
input.classList.toggle(
"correct",
input.value == answer
);
});
}
})();
</script>
Back template:
<span class="BackSide">
{{Front}}
<hr id=answer>
<div id="back">{{Back}}</div>
</span>
Styling section:
#typeans {
color: black;
}
#typeans.typed {
background-color: #ff9999;
}
#typeans.typed.goodsofar {
background-color: #ffff7f;
}
#typeans.typed.correct {
background-color: #99ff99;
}
.BackSide .type_answer {
font-weight: bold;
color: blue;
}
Basically, instead of using Anki’s default code for evaluating type input, I inserted a slightly modified version of the code found in this topic to have instant type answer feedback.
I also removed most of the type_answer code from the Back template.
The purpose of the class BackSide and this CSS .BackSide .type_answer { font-weight: bold; color: blue; }
is to highlight the content of the .type_answer span, to still have some sort of visual feedback.