For our KB Product Release Notes - we have specific categories that we want to count automatically. I settled on the solution of hiding 'counting' characters on the sections we want to count.
The initial code I developed was in a loop that was not obvious, so I sought help to redevelop the code to this but now it does not count at all. I am convinced it's something obvious that I am missing - because this works on a normal website. The folk that were assisting me before are not familiar with zendesk - so I thought to reach out to this community.
This is the script function:
<script>
function findOccurrences(string){
return [...document.querySelector("div").textContent.matchAll(string)].length;
};
document.addEventListener("DOMContentLoaded",()=>document.getElementById("anm_tot").textContent=
findOccurrences('¤'));
document.addEventListener("DOMContentLoaded",()=>document.getElementById("asm_tot").textContent=
findOccurrences('§'));
document.addEventListener("DOMContentLoaded",()=>document.getElementById("akb_tot").textContent=
findOccurrences('~'));
</script>
Then within the page:
<span id="anm_tot" class="wysiwyg-font-size-normal"> </span> (as an example).
What the page currently shows is a result of 0 in the place a count is expected.