0

I'm creating a basic AMP site, after the XMLHttpRequest that loads the product details I change the web content using javascript:

document.getElementById("stock").innerHTML = result.ref

This is the right approach for this new framework?

But what about the images? It recognises only the <amp-img> ID tag, not it child (standard <img>).

I've tried this way with no success:

document.getElementById("stock").src = "PATH_TO_MY_SITE" + result.ref + ".png"

It shows this error: Either non-empty "srcset" or "src" attribute must be specified:

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
rjcpereira
  • 943
  • 4
  • 17
  • Does `console.log("PATH_TO_MY_SITE" + result.ref + ".png")` produce a valid image url? – James May 16 '17 at 16:05
  • Yes, it shows the right url, I've tried it. I've added a console error at the end of my question – rjcpereira May 16 '17 at 16:13
  • Do you load it originally with an empty `src` attribute and update the DOM with JS later? Maybe it's complaining about the original empty/non-existent src attribute on page load? When you say **it** shows this error - what is **it**? – Adam Jenkins May 16 '17 at 16:15
  • The error was: `Either non-empty "srcset" or "src" attribute must be specified:`, I've added a "default image", but still doesn't show the "dynamic" image – rjcpereira May 16 '17 at 16:31

0 Answers0