Create a file hello.html with the following content:
Open this file in a web browser. As a result you will see a page with the text: Hello, World!
Explanation of code
1. Loads the jQuery library from the jQuery CDN:
This introduces the $ global variable, an alias for the jQuery function and namespace.
Be aware that one of the most common mistakes made when including jQuery is failing to load the library BEFORE any other scripts or libraries that may depend on or make use of it.
2. Defers a function to be executed when the DOM (Document Object Model) is detected to be "ready" by jQuery:
3. Once the DOM is ready, jQuery executes the callback function shown above. Inside of our function, there is only one call which does 2 main things:
1. Gets the element with the id attribute equal to hello (our selector #hello). Using a selector as the passed argument is the core of jQuery's functionality and naming; the entire library essentially evolved from extending document.querySelectorAllMDN.
2. Set the text() inside the selected element to Hello, World!.
# ↓ - Pass a `selector` to `$` jQuery, returns our element
# ↑ - Set the Text on the element