yas
Phoenix: $ is not defined
Hello,
I have a template which holds a form with a few elements. I need to initialize the JS for some of these elements using jquery, but I keep getting an error saying: “$ is not defined”. I followed all the steps in this post: Setup, import and use Javascript in Phoenix and also from the official Phoenix docs.
Here is the npm section of my brunch-config.js:
npm: {
enabled: true,
whitelist: ["jquery"],
globals: {
$: 'jquery',
jQuery: 'jquery'
}
}
Here is how I am calling the script from my template:
<script>
$('.ui.tags.dropdown').dropdown({
keys: {delimiter: 13},
allowAdditions: true
});
</script>
Please let me know if I can provide more information.
Any help would be much appreciated, thanks in advance!
Marked As Solved
OvermindDL1
Remember that things compiled into modules are not available at global scope nor should they be. Instead of doing things like $... you should be doing things like require("jQuery")... (if using brunch) or so (which you can bind to a variable if you want).
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








