you need to do this in JS. also in CSS, you must set a default background color otherwise the previous card’s style is erroneously unchanged for the next card.
<script>
var tags = "{{Tags}}".split(' ');
var mapping = {};
var elm_card;
mapping['mytag'] = function() {
elm_card.style.backgroundColor = '#b5ead7';
};
async function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function run() {
if (document.readyState == 'complete') {
elm_card = document.querySelector('.card');
for (tag of tags) mapping[tag]?.();
}
// not fully loaded, try again in 0.1ms
await delay(100);
run();
}
run();
</script>
ah, i got the bug wrong. you need to reset the elm_card.style.backgroundColor in JS instead of CSS, as setting it from JS also sets the inline style attribute.
another approach could be to create a <style> element with the style you want. that’d allow for Anki to clear out the contents automatically instead of manually resetting the style.