+ 1
$ in JavaScript
How do I use the $ in JavaScript. Everytime I try it says I have and error. Ideas?
4 ответов
+ 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.
+ 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.
+ 2
Do you mean for jQuery?
+ 1
Well yes but people use it in JavaScript