Please help with data attributes

I have no idea why JS cannot understand the data-img attributes. It should be simple, but I’m missing something here. Please check codepen for the example

  1. The images come from the backend, so they are put inside “data-img” attribute.
  2. Js reads the data-img
    3 Js process it.

However, nothing happnes. Any clue?

Thank you!

What are you trying to accomplish?

I’m using the FileUploadWithPreview library to preview form images. In this particularly case, I want to preview already uploadED images. That’s why I’m feed data-img with the images from DB. So, I can use JS to read that, and use the presetFiles option from the library to show those images.

You can make it a comma-separated list of URLs and split it on the comma (lib docs).



It doesn’t work on Codepen.

Works just fine for me.

You are right. It worked!


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.