Can't get jquery plugin to work

Electron version: 1.2.0
Operating system: OS X

Hello, I’m trying to use the jquery plugin chosen in my electron app. When I look at sources in the developer panel I see the chosen js has loaded, but then when I try to invoke the code I get the following error:

Uncaught TypeError: $(…).chosen is not a function
Here’s how I’m loading it up from index.html:

 window.$ = window.jQuery = require('jquery');
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
<script>if (window.module) module = window.module; var $ = require('jQuery');</script>
<script src="./chosen/chosen.jquery.min.js"></script>

I also tried using this line instead, but then the file doesn’t even get loaded up:

Jquery works perfectly, BTW.

What is ./chosen/chosen.jquery.min.js?

window.$ = window.jQuery = require(./wherever-jquery-is/jquery.min.js);” should work.

Chosen is a jquery plugin:

Oh, I see, so when you say jQuery’s working, it’s that jQuery works, but this plugin doesn’t.

Is it a scoping issue? Because you’ve got var $ = ..., when you’re already setting it on window up top? So the plugin is using the one on window, but you’re calling the ‘scoped’ var?

I managed to get jQuery working by including it as a script in the html. Ensure that it’s included first before your other jquery plugins.

    <meta charset="UTF-8">
    <title>My App</title>
    <script type="text/javascript" src="./node_modules/jquery/dist/jquery.min.js" onload="window.$ = window.jQuery = module.exports;"></script>
    <script src="./node_modules/bootstrap-sass/assets/javascripts/bootstrap.js"></script>
    <script src="./node_modules/hammerjs/hammer.min.js"></script>
    <script src="./node_modules/velocity-animate/velocity.min.js"></script>
    <link href="css/index.css" rel="stylesheet" type="text/css" />
1 Like

This was a lifesaver - completely solved my issue - thanks!!