Add jQuery to your NextJS App

The best way is to add jQuery via npm and include the inject file in the root file. Let me show you how.

npm install jquery --save
//inject.js
window.$ = window.jQuery = require('jquery')
import '[PathToFile]/inject.js'

const getPrincipalAmount= () => {
  $("#principalAmount").val("data");
}

or you can also try this approach

import React from 'react';
import $ from 'jquery';

$("p").click(function(){
    alert("The p tag was clicked.");
  });

// react component here

Leave a comment

Your email address will not be published. Required fields are marked *