Book Image

jQuery for Designers: Beginner's Guide

By : Natalie Maclees
Book Image

jQuery for Designers: Beginner's Guide

By: Natalie Maclees

Overview of this book

jQuery is awesome for designers ñ it builds easily on the CSS and HTML you already know and allows you to create impressive effects with just a few lines of code. However, without a background in programming, JavaScript ñ on which jQuery is built ñ can feel intimidating and impossible to grasp. This book will show you how simple it can be to learn the basics and then extend your capabilities by taking advantage of jQuery plugins.jQuery for Designers offers approachable lessons for designers with little or no background in JavaScript. The book begins by introducing the jQuery library and a small and simple introduction to JavaScript. Then you'll step through a few simple tasks to get your feet wet before diving into using plugins to quickly and simply add complex effects with just a few lines of code.You'll be surprised at how far you can get with JavaScript when you start with the power of the jQuery library and this book will show you how. We'll cover common interface widgets and effects such as tabbed interfaces, custom tooltips, and custom scrollbars. You'll learn how to create an animated navigation menu and how to add simple AJAX effects to enhance your site visitors' experience. Then we'll wrap up with interactive data grids which make sorting and searching data easy.
Table of Contents (19 chapters)
jQuery for Designers Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – downloading and attaching jQuery


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:

  1. First, let's set up a folder on your hard drive to hold all of your work as you work through the lessons in this book. Find a good place on your hard drive and create a folder called jQueryForDesigners.

  2. Inside the folder, create a folder called 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.

  3. Next, create a folder called 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.

  4. Now, inside the 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.

  5. Next, we'll attach the CSS and JavaScript files that we made to our HTML page. In the head section, add a line to include the CSS file:

    <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

    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.

    Here's what my folder looks like at this point:

  6. Now we have to include jQuery in our page. Head over to http://jq uery.com and hit the Download(jQuery); button:

    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.

  7. Clicking on the Download button will open the production jQuery file in your browser window, and it looks a little bit scary, as follows:

  8. Don't worry, you don't have to read it and you definitely don't have to understand it. Just go to your browser's file menu and choose Save Page As... or right-click on the page and select Save As and then save the file to your hard drive, inside the 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.

  9. Now we just have to include our jQuery script in our page, just like we included our empty JavaScript file. Go to the bottom of your practice HTML file, just before the <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.