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)

20th Dec 2018, 6:11 AM
Yoran 2004
Yoran 2004 - avatar
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/
20th Dec 2018, 6:13 AM
Gordon
Gordon - avatar