With this code below, I get an error: $ is not defined. My question is: How it is possible?
$ is not defined
...
You're not including the jQuery JS until the end of the page but you're trying to make use of $ well before you've included it.