Adding a jQuery Library to Magento 2

Here is a step-by-step process for adding a jQuery library to Magento 2:

Download the jQuery library file from a reliable source, such as the official jQuery website.
Log in to your Magento 2 backend and go to the “Stores” menu and then click on “Configuration.”
In the left-side menu, expand the “Advanced” section and select “Developer.”
In the “JavaScript Settings” section, select “Yes” for the “Merge JavaScript Files” option.
In the “JavaScript Library” section, select “jQuery” as the library to use.
Save your changes by clicking on the “Save Config” button.
Create a new file in the following directory:



In this file, paste the following code:


], function($){
'use strict';

// your custom code here

Add your custom jQuery code within the function.

Save the file and clear the cache to see your changes take effect.

Note: The file path and the name of the jQuery library may vary depending on the version of Magento 2 you are using.