cancel
Showing results for 
Search instead for 
Did you mean: 

Can anyone help me ?

Can anyone help me ?

I am trying to use JQuery in my block functions, but I get an error saying JQuery not found. I tried google and some suggested to add it to local.xml but I think Magento2 does not have local.xml.

 

Can anyone help me on how to enable JQuery in Magento2?

 

Thanks

2 REPLIES 2

Re: Can anyone help me ?

hello @vertu_uneuo

put your javascript code inside require function like below code


require(['jquery', 'jquery/ui'], function($){

     //your javascript code here

});

 

If my answer is useful, please Accept as Solution & give Kudos

Re: Can anyone help me ?

Hi @vertu_uneuo 

 

You can create a local.xml file in your theme on this path.

 

app\design\frontend\themePackage\themeName\Magento_Theme\layout\local.xml

OR if you want to add direct JQuery in block/phtml file. You need to add code inside require function. See below example.

 

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

I think it will help you.

 

Thanks

 

--

If my answer is helpful, please Accept as Solution & give Kudos