How to add Jquery to Electron?

Asked

Viewed 2,040 times

2

I’m web developer, I’ve tried methods in an English post, but... none works, I want to add Jquery in the electon.

I’ve used this one without window.$ doesn’t work.

<script src='https://code.jquery.com/jquery-3.2.1.min.js'></script>

I tried with window.$ was working but stopped working for some unknown reason...

<script src='https://code.jquery.com/jquery-3.2.1.min.js' onclick='window.$ = window.jQuery = module.exports;'></script>

Does anyone know any script to make Jquery work?

I want to leave him in mine main.js (index.js) instead of leaving it on a web page if possible. If it doesn’t, I leave it on the web page itself.

  • Have you ever tried something like const $ = require('jquery')?

1 answer

5

You need to use the Node to install jQuery so you can use it on the server-side.

See below:

npm install jQuery

Then just include the jQuery package (like suggested by Anderson Carlos Woss):

var $ = require('jQuery');

In the illustration example below, I include the package in the file index.html, however, you can include in your main.js or in a separate window.

<script>
    // You can also require other files to run in this process
    require('./renderer.js')
    var $ = require('jQuery');

    // Pode usar o jQuery normalmente agora.
    $(document).ready(
        function() 
        { 
            $("<h1>Test jQuery</h1>").appendTo('body');
        }
    );
</script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.