0
Why doesn't a Jquery code work outside a function?
I had a code ($(#AnId).text("text")) outside of a function but it didn't work, instead it gave an error ($ is not defined)
1 Odpowiedź
0
The reason is you try to add text to a DOM before it exists.
Wrap your codes in:
$(document).ready(function() {
... your codes...
});
or short-handed:
$(function() {
... your codes...
}) ;
https://www.sololearn.com/learn/jQuery/2785/