Notification texts go here Contact Us Buy Now!

How to properly use this jQuery script in my Next.Js app?

To fully utilize the jQuery script within your Next.Js application, follow these steps:

  1. Install jQuery using the command:
    npm install jquery
    
  2. Create a loader.js file and add the following code:
    
    window.$ = window.jQuery = require('jquery')
    
  3. Import the loader.js file:
    
    import '[LoaderPath]/loader.js'
    
  4. Now, you can use jQuery within your components:
    
    const handleForm = () => {
      $("#date").val("data");
    }
    

Alternatively, you can place the jQuery script tag directly in your _document.js file, as shown in this example from pages_document.js:


import Document, { Html, Head } from 'next/document'

class MyDocument extends Document {
  render() {
    return (
      <Html lang="id">
        <Head>
          <meta name="robots" content="noindex, nofollow"/>
          <meta name="referrer" content="no-referrer-when-downgrade"/>
          <script src="/assets/js/jquery.min.js"></script>
        </Head>

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.