Add custom jQuery scripts to your templates

Wondering how to add a custom jQuery script to your magento 2 phtml template files?

You will above to include the javascript code inside a require function. Here is how:

<script>
 require(['jquery', 'jquery/ui'], function($){ 
     //your js code here. Use $ to access the jQuery library
 });
</script>

That is it! Simple 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *