I have created my custom module in that a particular .phtml file i want to apply my custom JS
please suggest as soon as possible
Solved! Go to Solution.
Hi @asd_asd46
If you want to add js with phtml file then you can consider below code and add with phtml file
<script> require(['jquery', 'myscript'], function($, myscript) { cosole.log("testing"); }); </script>
Or you can refer below link :
https://magento.stackexchange.com/questions/301627/magento-2-how-to-include-custom-js-file-in-phtml-...
If issue resolve, please click on 'Kudos' & Accept as Solution!
Hi @asd_asd46
If you want to add js with phtml file then you can consider below code and add with phtml file
<script> require(['jquery', 'myscript'], function($, myscript) { cosole.log("testing"); }); </script>
Or you can refer below link :
https://magento.stackexchange.com/questions/301627/magento-2-how-to-include-custom-js-file-in-phtml-...
If issue resolve, please click on 'Kudos' & Accept as Solution!
Hi @asd_asd46,
Can you please check below link:
https://inchoo.net/magento-2/custom-javascript-in-magento-2-with-requirejs/
Hope this helps you.
Problem Solved! Click kudos & Accept as Solution!
Thank you for valuable suggestion.Give sample code is working in my .phtml file
But i have 2 files
1) Jacker_scroller.js and 2) jquery.pagepepling.js
i want to include these both files in .phtml please suggest on this
Hi @asd_asd46 ,
Can you please try below codebase in your phtml file
require(['jquery', 'VendorName_ModuleName/js/Jacker_scroller', 'VendorName_ModuleName/js/jquery.pagepepling'], function($, jackscroller, pagepepeling) {
cosole.log("testing");
});
Note: 1. Please replace VendorName_ModuleName with your custom module.
2. Also, try to use lower case letters in js names.
For more details, you can follow below link:
Hope it helps you!
Problem Solved! Click Kudos & Accept as Solution!