function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Leticia Monteiro Freitas 4Leticia Monteiro Freitas 4 

jquery in lighting component

Hello, 

I'm trying to pass a jquery file for an lightning component.
 
<!--HTML-->  
<ltng:require scripts="{!$Resource.jQuery2}" afterScriptsLoaded="{!c.doInit}" />
 
doInit : function(component, event, helper) {
        
        jQuery("document").ready(function(){console.log('loaded');});
}

But I'm getting the following error:
[jQuery is not defined] - I​​ JS didint recognize the jquery. Can anyone help me?
 
Alain CabonAlain Cabon
Hello,

How did you create your resource jQuery2 ?

You can try an alternative:

 <ltng:require scripts="{!$Resource.jQuery2 + '/jquery-3.3.1.min.js'  }" />
 
Raj VakatiRaj Vakati
Refer this link 

https://rajvakati.com/2018/05/29/using-jquery-in-lightning-components/

 
Deepali KulshresthaDeepali Kulshrestha
Hi Leticia,
Refer to these Links:

-->http://sfdcmonkey.com/2018/03/13/jquery-datatable-salesforce-lightning-component/
-->https://jennamolby.com/how-to-use-jquery-libraries-within-salesforce-lightning-components/
-->http://salesforcetechhub.blogspot.com/2017/01/how-to-use-jquery-in-lightning.html

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks.
Deepali Kulshrestha