How to use JQuery in Sharepoint Framework (SPFx)
This article will walk you through on how you can add and use JQuery on you SharePoint Framework web part.
To get things started:
- Open your SPFx project using Visual Studio Code.
- Open up a terminal and execute the following commands:
- npm i jquery
- npm i @types/jquery
- After executing the commands, open up your web part component.
- To be able to use JQuery, add import * as $ from ‘jquery’ in your code. Then add ${$.fn.query} to test that JQuery works in your web part.
- Now that all are setup, you can now test your web part by running gulp serve on the command line.
- You will now see that the web part used JQuery and shows the version