0

On this web page, https://editart2020.crooked.media/collection/fundamentos/, mouse over the first image to see the caption -- it has a comma and the word "by".

I got that with this simple code:

    const caption = document.querySelector('.ae-overlay-caption').innerHTML;
    caption2 = caption.replace("<br>",",<br>by ");
    document.querySelector('.ae-overlay-caption').innerHTML = caption2;

Now when I try to get the other captions to work, I tried this code:

const captions = document.querySelectorAll('.ae-overlay-caption').innerHTML;
    for (var i; i < captions.length; i++) {
        caption[i] = captions.replace("<br>",",<br>by ");
        document.querySelector('.ae-overlay-caption').innerHTML = caption[i];
    }

However, the console says that captions is not defined. I don't know why and I've tried many variations of this code, and different for loops, to no avail. Thanks.

user42760
  • 85
  • 1
  • 7
  • 1
    An element will have an `innerHTML` property, a collection of elements won't. – Quentin Aug 10 '20 at 18:37
  • The same problem anyone has that comes from a jQuery background. – connexo Aug 10 '20 at 18:38
  • So how do I get the others? – user42760 Aug 10 '20 at 18:39
  • should be `caption[i] = captions[i].replace("
    ",",
    by ");`... where is caption comming from?
    – Lawrence Cherone Aug 10 '20 at 18:39
  • If I change the code to this: const captions = document.querySelectorAll('.ae-overlay-caption'); for (var i; i < captions.length; i++) { caption = caption[i].replace("
    ",",
    by "); document.querySelector('.ae-overlay-caption').innerHTML = caption; } I still only get the first one.
    – user42760 Aug 10 '20 at 18:45
  • const captions = document.querySelectorAll('.ae-overlay-caption'); console.log(captions); for (var i; i < captions.length; i++) { caption = caption[i].replace("
    ",",
    by "); document.querySelector('.ae-overlay-caption').innerHTML = caption; }
    – user42760 Aug 10 '20 at 18:46
  • I still only get the first caption – user42760 Aug 10 '20 at 18:46

0 Answers0