<body>
<div><span class="span" data-genres="a, b, c"></span></div>
<div><span class="span" data-genres="d, e, f"></span></div>
<div><span class="span" data-genres="g, h, i"></span></div>
<div><span class="span" data-genres="j, k, l"></span></div>
<script>
function addGenres(genres, container) {
genres.split(', ').forEach(genre => {
const linkNode = document.createElement('a');
const textNode = document.createTextNode(genre);
linkNode.setAttribute('href', `/category/${genre}`);
linkNode.setAttribute('class', 'content__box__genre--links');
linkNode.appendChild(textNode);
container.appendChild(linkNode);
})
}
</script>
<script>
document.querySelectorAll('.span').forEach(el => {
addGenres(el.dataset.genres, el)
})
</script>
</body>