Using jQuery in a Magento 2 static block or CMS page can be tricky, a special syntax is required. Use the following code to add jQuery when all the content was loaded:
1 2 3 4 5 6 7 8 |
<script> require([ 'jquery' ,'domReady!' ], function ($) { console.log('whatever'); }); </script> |
Of course, you can skip listening to domReady event! Just remove the domReady line, like this:
1 2 3 4 5 6 7 |
<script> require([ 'jquery' ], function ($) { console.log('whatever'); }); </script> |
Using jQuery and domReady in a static block or CMS page
You want or need help implementing this solution? Maybe you did not find what you were looking for? Contact me and I will assist you with whatever Magento problem troubles you!