jQuery not working for script in component
Question
Hi!
I have tried adding jquery in canvas as well as in index.html
I am adding it in canvas like this-
canvas = editor.Canvas; const script1 = document.createElement('script'); script1.src = 'https://code.jquery.com/jquery-3.6.0.min.js'; canvas.getDocument().head.appendChild(script1);
and in html page I have added it as script tag - <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
now , I have a component inside which I am defining a script.
editor.DomComponents.addType('foo-button', {
model: {
defaults: {
tagName: "button",
classes: 'foo',
//name: "Button",
content: "Button",
script: function() {
$('.foo').click(function(){
alert("Meow");
});
}
}
}
})
editor.BlockManager.add("button1", {
label: "Button",
content: { type: 'foo-button' }
});
but it is still giving me error - Uncaught ReferenceError: $ is not defined
What is it that I am doing wrong? Please help.
Answers (1)
Here you can see how to load dependencies properly https://grapesjs.com/docs/modules/Components-js.html#template-related
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3730
Script tag not rendering in HTML page
I created the component as below. site_1 - is my readymade template and it has CSS and javascript. CSS loads properly with the "content" bu...
Issue #3688
How to customize a component
I read this document https://grapesjs.com/docs/modules/Components.html#define-custom-component-type and tried to write the following code....
Issue #2667
link element not append in head element in ediot.canvas #firefox #grapesjs
am trying to add google fonts in web-builder to change the font style for that to import am adding cdn in editor the code works in chrome a...
Issue #1671
[Question] Adding html once canvas is cleared.
Hey Artur I'd like to add some default html code when users click clear button. for instance 1 section by default. for clear command, i'm d...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.