Remove an Image when on preview and show on editor
You can't just do $('.img[src=""]') GrapesJS components are not in the same context, are placed inside an iframe so you have to use the document from that iframe, eg.
Read full answer below ↓Question
Hey, @artf I need help with a challenge I've been facing
I want to hide images with src empty for particular class images in preview mode and show them on editor mode.
I've tried this but it doesn't seem to work for some reason
editor.on('run:preview', () => {
$('.img[src=""]').hide();
});
editor.on('stop:preview', () => {
$('.img[src=""]').show();
});
Thanks, Chaitu
Answers (2)
You can't just do $('.img[src=""]') GrapesJS components are not in the same context, are placed inside an iframe so you have to use the document from that iframe, eg.
editor.Canvas.getDocument().querySelectorAll('.img[src=""]')
is your selector correct? As far as i know grapes will set background-image:url() instead of src.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #426
After image Upload immediately show in the asset Manager
@ artf I tried my best, but still it doesn't seem to work Can you please help me in this. Once I upload a image I don't want to refresh the...
Issue #1322
Disable editing in Preview Mode.
@artf How can we disable editing in the preview mode and re-enable it when preview mode off. I want to remove editor and hide toolbar in th...
Issue #3173
How to remove the eye-slash button in preview mode?
Hi @artf ! I have created a web builder using GrapesJS. I want to remove the eye-slash button in preview mode and replace it with the back...
Issue #1218
[QUESTION] Asset Manager - Upload Image
Hey @artf , I have a question around Asset Manager. When uploading an image via computer or url the preview shows up at the asset collectio...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Related tutorials
In-depth guides on the same topic.
Tutorial
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Tutorial
GrapesJS Inline RTE Plugins Update: CKEditor 5 v0.1.4 and Froala Inline Text Editor
CKEditor 5 Inline for GrapesJS v0.1.4 fixes Studio SDK toolbar clipping, iframe injection and link balloon bugs. Compare with Froala Inline — both $69.
Tutorial
Embed GrapesJS in Your SaaS: A Weekend Guide
Embed GrapesJS in your SaaS and ship a white-label page builder over a weekend. Honest tradeoffs, real code, and the plugins that close the UX gap.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.