Add event and getJs for a component
Hi @dat15021999 GrapesJS doesn't have support for javascript code, only html and css. Although, you can retrieve all js code by running editor.getJs() function.
Read full answer below โQuestion
Hi artf, I'm newbie with this Grapesjs. How to add event for a component and get the corresponding javascript or jquery ? Thank all
Answers (2)
Hi @dat15021999
GrapesJS doesn't have support for javascript code, only html and css.
Although, you can retrieve all js code by running editor.getJs() function.
You can use something like: To add an event for example you set code to: You can check out grapesjs-script-editor and grapesjs-blockly plugins. EDIT: You should use target.getScriptString() instead of target.get('script').
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3399
Convert JSON to HTML server-side
So first of all, thank you @artf for this amazing project. I have a question: Is it possible to easily convert the components-JSON to HTML...
Issue #2083
Model.get('toolbar') always return null
Hi @artf I am trying to add a custom toolbar to my custom component without changing the default toolbar. So I expect it to be like [movabl...
Issue #1409
Component Drag Event
I want to know how can I get that component from which element is dragged and drop to the other component. I need to add a class if compone...
Issue #2238
How to get style for header & footer components only
Hi @artf, can you please tell me what is the fastest and easies way to extract component styles. I have template and in this template you c...
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
GJS.Market Is Now Available for India ๐ฎ๐ณ
GJS.Market is expanding its global presence with a dedicated experience for developers, agencies, SaaS companies, and digital creators in India
Tutorial
How to Build an AI-Powered Page Builder with GrapesJS in 2026
What we learned building GJSDocs โ from simple AI text generation to structured, context-aware visual editing
Tutorial
How Much Does It Cost to Build a SaaS Page Builder in 2026?
How much does it cost to build a SaaS page builder in 2026? Explore realistic development costs, timelines, features, and how using GrapesJS can reduce
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.