Why is using Y.all with each (function) returns only one element translated

33 Views Asked by At

I'm working with SquareSpace and I am trying to translate blog posts meta dates in French, on the summary page where all the posts appear. I was using a logic where I get all the elements within a class and for each one having this function returning the translated date. For some reason, it returns only the first translated date and not the other ones. I've looked for days on different forums to try to find the reason why, but so far found no answers. I could really use some help to figure it out. Here is the script I used:

<script>
Y.on('domready', function () {
Y.all(".Blog-meta-item.Blog-meta-item--date").each(function(){
  var postDate = Y.one("time").getAttribute("datetime");

  var postYear = postDate.substring(0,4);
  var postMonth = postDate.substring(5,7)-1;
  var postDay = postDate.substring(8,10);

  var transDate = new Date(postYear, postMonth, postDay);
  var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
  var dateString = transDate.toLocaleDateString('es-ES', options);

  Y.one("time").setHTML(dateString);
  });
}); 
</script>
0

There are 0 best solutions below