How to replace srcset ? #6201
-
In GrapesJS, I'm importing an HTML page that contains an image with a srcset attribute. When I try to replace the image, my new image link always goes into the src attribute instead of srcset. How can I fix this? Please help. |
Beta Was this translation helpful? Give feedback.
Answered by
mohamedsalem401
Oct 16, 2024
Replies: 1 comment 1 reply
-
Hey, sorry for late response. editor.on('component:update:src', (component) => {
if (component.get('tagName') !== 'img') return
component.addAttributes({ 'srcset': component.getAttributes().src })
}); If you want to set the editor.on('component:mount', (component) => {
if (component.get('tagName') !== 'img') return
component.addAttributes({ 'srcset': component.getAttributes().src })
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
asimex
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Hey, sorry for late response.
Please try the following snippit
If you want to set the
srcset
after loading the component, just add