Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use jQuery in my html after npm install? [duplicate]

Tags:

jquery

npm

After running npm install jquery, what then? I have tried:

import $ from "jquery.js";
var $ = require("jquery.js");

This code is in my app.js file which is connected to my html. jQuery code I write has no affect on the DOM.

like image 923
ksingh Avatar asked Oct 23 '25 07:10

ksingh


1 Answers

Just use it like this:

import $ from 'jquery';

$(function () {
  // ...
});

If you use express add this as static route

app.use('/lib/jquery', express.static(path.join(__dirname, 'node_modules/jquery/dist')));

And load it in your html file:

<script src="/lib/jquery/jquery.min.js"></script>

Maybe you have to modify the pathes.

like image 174
ztom Avatar answered Oct 26 '25 01:10

ztom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!