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
You can set your jquery inside Block PHP file,
$customJs = " require(['jquery'], function($){ $(document).ready(function(){ // code your javascript here }); }); ";
Hi @hgff_fghdfg
By default jQuery is always there and added in magento platform.
However if you would like to use the jQuery in the Block file, then you must require to load jQuery in the block file, using below code you will able to load and put the js code on JS event :
$YourJsName = " require(['jquery'], function($){ }); ";
Note : Just one suggestion , jQuery always needs to use in view(phtml) file, if you don't have strict complex logic , then try to load and use it in the phtml file only.
Hope it helps