Trying to add a text before the image on all cards, in a dynamic page. there are 1700 images so ı thought it's only doable via javascript, since it's on Google Optimize, only vanilla is allowed.
I put this:
var images = document.querySelectorAll(".car-card .car-card__image");
images.forEach(function(image){
image.before("Hello world");
});
It actually puts the text, but when I check it via debug mode, it's adding the text for forever, so I see,
Hello worldHello worldHello world....
How to fix this?
Cheers
you need create a empty tag before any image and put the text in it.
in yuor Html:
and in yout javascrtipt code
But if you can't add a tag before the photo, there is another way that is not interesting
})