Hello,
I would need to make a function that is triggered when a user clicks on one of the Table of Contents elements.
I have identified the elements that are generated via the “Table of Contents” element of Bricks, namely the <a>
tag that contains the “.toc-link” class.
For this I made a script of this type:
<script>
const tocLinks = document.querySelectorAll('.toc-link');
tocLinks.forEach((tocLink, index) => {
tocLink.addEventListener('click', () => {
myFunction(index);
});
});
</script>
After several tests, I noticed that the method document.querySelectorAll('.toc-link');
does not select any elements.
Can you help me understand why? Thank you.