Skip to content
NewRedesigned blogFeedback
Jigar Karangiya

How to use jQuery in Magento 2?

You can use the JQuery library in Magento 2 by adding code inside require function and you can also access it in the console by $ sign.

How to use jQuery in Magento 2?
Written by
JKJigar Karangiya
Published
Reading time
1 min read

Jigar Karangiya · · 1 min read

jQuery (opens in new tab) 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 :

javascript
require(['jquery', 'jquery/ui'], function($) {
    //your js code goes here 
});

Here is an example :

javascript
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.

Figure 01Demonstrating use of jQuery Library in browser console
Demonstrating use of jQuery Library in browser console

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 !! 🙂

Keep reading
All posts

01 · 10 min · Shares Adobe Commerce Core

Adobe Commerce Agentic Capabilities, Q4 2026

Five agentic releases for Adobe Commerce: LLM product discovery, Brand Visibility, the Shopper MCP server, Brand Concierge, and Experience Workspace. What each one does, which editions get it, and when.

10 min

03 · 3 min · Shares Adobe Commerce Core

Conditions for Collections in Magento 2

Collections in Magento 2 (Now Adobe Commerce), are among the most powerful tools for retrieving and manipulating data directly from the database.

3 min

Newsletter

New Magento tutorials, straight to your inbox

Code examples, performance tips, and fixes for common Magento issues. No spam.

Subscribe