I have a number of translations to do on a page (worpress site) and I want to do it using javascript rather than get into php code. So I have a number of similar actions to be done where I select a class using getElementsByClassName which returns an HTML collection then turn that into an Array and then use a forEach function to change the textContent. Simple enough and it works:
let verMas = document.getElementsByClassName('read-more-button');
let verMasA = Array.from(verMas);
verMasA.forEach(function(verMasL){
verMasL.textContent = 'Ver mas...';
});
The problem is that I have several of these little translations to do ALL basically the same action so the obvious solution is to turn the above into a function but I am not getting it right. This is what I did:
function traducirArray(a,cla,b,c,d) {
let a = document.getElementsByClassName(cla);
let b = Array.from(a);
b.forEach(function(c){
c.textContent = d;
return d;
});
}
traducirArray(verMas, 'read-more-button',verMasA,verMasL,'Ver más');
At the end I call the function but it is not working. What am I doing wrong?