+ 1

$ in JavaScript

How do I use the $ in JavaScript. Everytime I try it says I have and error. Ideas?

24th Aug 2017, 9:53 PM
Caden Schindler
Caden Schindler - avatar
4 Answers
+ 7
you need to add a link to the jQuery CDN inside the head tag of your document if you want to use jQuery on your site. eg: <script src="https://code.jquery.com/jquery-3.1.1.js"></script> or you can also download it as a file and then link it to your document.
24th Aug 2017, 11:04 PM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
+ 4
Usually you would just include the jQuery(library) script above the JS script(in html file) but as SoloLearn includes the JS automatically before you can include anything else what I did was (in JS) window.onload = function () { //the JQuery code here } then in the header tag of the html window i put <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> which includes the jQuery library before the JS file does anything. I'm not sure if there's a better way of doing it other than not using SoloLearn.
24th Aug 2017, 11:04 PM
Enzo
Enzo - avatar
+ 2
Do you mean for jQuery?
24th Aug 2017, 10:07 PM
Enzo
Enzo - avatar
+ 1
Well yes but people use it in JavaScript
24th Aug 2017, 10:43 PM
Caden Schindler
Caden Schindler - avatar