jQuery is a lightweight, JavaScript library. The purpose of jQuery is to make it much easier to use JavaScript on your website. The jQuery library is available for you in default Magento 2 itself!
How to Use Magento jQuery Library?
To add the Magento jQuery library, you need to contain the jQuery code inside require function as below :
require(['jquery', 'jquery/ui'], function($) {
//your js code goes here
});
Here is an example :
require(['jquery', 'jquery/ui'], function($){
$(document).ready( function() {
alert("Hello from Jigar Karangiya.");
});
});
You can also use the above code in the browser console for direct execution and testing purposes and access elements using $ sign.
You may also like :
How to use ifconfig in layout xml Magento 2?
How to Get Store Configuration value in Magento 2?
That’s it for this tutorial, See you in the next blog. Happy Coding !! 🙂
Leave a Comment