Closed dat15021999 closed 4 years ago
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:
const target = editor.getSelected();
const code = target.get('script') || '';
// some logic to view and edit code
targer.set('script', code);
To add an event for example you set code to:
const el = this;
el.addEventListener('event', eventHandler);
function eventHandler(e) {
// handle event
};
You can check out grapesjs-script-editor and grapesjs-blockly plugins.
EDIT:
You should use target.getScriptString()
instead of target.get('script')
.
Hi artf, I'm newbie with this Grapesjs. How to add event for a component and get the corresponding javascript or jquery ? Thank all