Selective Card Generation based on content of field?

Hi!

I tried to find a way to use the selective card generation method based on the content of a field (div) rather than if the field is empty or not as it is described in the Anki manual.

https://docs.ankiweb.net/templates/generation.html#selective-card-generation

I didn’t succeed.

That was my approach:

The note type contains a field that is empty per default {{emptyfield}}.
The card is wrapped in 2 card generator divs, at start and end.

HTML

<div class="cardgenerator_start"></div>

<div class="target">
<span class="fourth">Die Arbeiten</span> <span class="lex3">müssen</span> <span class="second">bis Mitte <span class="first">Mai</span></span> <span class="third">abgegeben werden</span>.</span>
</div>

<div class="cardgenerator_end"></div>

JQuery for Card Type2

<script>
/*if target does not contain child div .second, then append emptyfield in curly brackets */

if ($('.target > .second').length == 0) {
	$(".cardgenerator_start").append('\u007B\u007B#emptyfield\u007D\u007D');
}

/*if target does not contain child div .second, then append emptyfield in curly brackets */
if ($('.target > .second').length == 0) {
	$(".cardgenerator_end").append('\u007B\u007B/emptyfield\u007D\u007D');
}

</script>

JQuery for Card Type3

<script>
/*if target does not contain child div .third, then append emptyfield in curly brackets */

if ($('.target > .third').length == 0) {
	$(".cardgenerator_start").append('\u007B\u007B#emptyfield\u007D\u007D');
}

/*if target does not contain child div .second, then append emptyfield in curly brackets */
if ($('.target > .third').length == 0) {
	$(".cardgenerator_end").append('\u007B\u007B/emptyfield\u007D\u007D');
}

</script>

The idea behind is that this could be a cloze deletion workaround based on a basic card template that would also allow cloze overlapping.

(eg. “Mai” (cloze1) overlaps with “bis Mitte Mai” (cloze2))

Thanks!