Earlier, I described the three layers of an HTML document — content, presentation, and behavior. Let's take a look at how we can set up our files for these three layers:
jQueryForDesigners
. styles
. We'll use this folder to hold any CSS we create. Inside the styles
folder, create an empty CSS file called styles.css
.The styles represent our presentation layer. We'll keep all of our styles in this file to keep them separate. Likewise, create a folder called images
to hold any images we'll use.
scripts
to hold our JavaScript and jQuery code. Inside the scripts
folder, create an empty JavaScript file called scripts.js
.The JavaScript we write here represents our behavior layer. We'll keep all of our JavaScript in this file to keep it separate from the other layers.
jQueryForDesigners
folder, create a new HTML page very basic as follows:<!DOCTYPE html> <html> <head> <title>Practice Page</title> </head> <body> <!-- Our content will go here --> </body> </html>
Save this file as index.html
. The HTML file is our content layer — and arguably the most important layer; as it's likely the reason site visitors are coming to our website at all.
<head>
<title>Practice Page</title>
<link rel="stylesheet" href="styles/styles.css"/>
</head>
And then head down to the bottom of the HTML file, just before the closing </body>
tag and include the JavaScript file:
<script src="scripts/scripts.js"></scripts>
</body>
</html>
As these files are just empty placeholders, attaching them to your HTML page won't have any effect. But now we have a handy place to write our CSS and JavaScript when we're ready to dive into an exercise.
Note that it's perfectly fine to self-close a<link>
element, but a<script>
element always needs a separate closing</script>
tag. Without it, your JavaScript won't work.
You'll notice you have two options under Choose Your Compression Level. You'll always want to check the Production checkbox. This is the version that's ready to use on a website. The Development version is for experienced JavaScript developers who want to edit the source code of the jQuery library.
scripts
folder we created. By default, the script will have the version number in the file name. I'm going to go ahead and rename the file to jquery.js
to keep things simple.<script>
tag we created earlier and add a line to include jQuery:<script src="scripts/jquery.js"></script>
<script src="scripts/scripts.js"></script>
</body>
</html>
You won't notice any changes to your HTML page — jQuery doesn't do anything on its own. It just makes its magic available for you to use.
3.22.248.208