Book Image

jQuery for Designers Beginner's Guide Second Edition

By : Natalie Maclees
Book Image

jQuery for Designers Beginner's Guide Second Edition

By: Natalie Maclees

Overview of this book

Table of Contents (21 chapters)
jQuery for Designers Beginner's Guide Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

JavaScript basics


In this section, we're going to cover a few basics of JavaScript that will make things go more smoothly. We're going to look at a little bit of code and step through how it works. Don't be intimidated; this will be quick and painless, and then we'll be ready to get on with actually doing something with jQuery.

Progressive enhancement and graceful degradation

There are a few different schools of thought when it comes to enhancing your HTML pages with JavaScript. Let's talk about some of the things we should consider before we dive into the cool stuff.

Progressive enhancement and graceful degradation are essentially two sides of the same coin. They both mean that our page with its impressive JavaScript animations and special effects will still work for users who have less capable browsers or devices. Graceful degradation means that we create our special effect and then make sure it fails gracefully if JavaScript is not enabled. If we take the progressive enhancement approach, we'll first build out a bare bones version of our page that works for everyone, and then enhance it by adding our JavaScript special effects. I tend to favor the progressive enhancement approach.

Why should we care about users who don't have JavaScript enabled? Well, some of the Web's biggest users and search engines have either no JavaScript capabilities or very limited JavaScript capabilities. When search engines are crawling and indexing your pages, they will not have access to all of the content and features that are being added to your pages by JavaScript. This is often referred to as dynamic content, and it can't be reliably indexed or found by search engines if it can't be reached with JavaScript disabled.

We're also in an era where we can no longer count on users who access the web pages we build with a conventional desktop or laptop computer. We're quick to think of smartphones and tablets as the next candidates, and while they are very popular, they still account for a tiny fraction of Internet access. People are accessing the Web from gaming consoles, feature phones, e-book readers, internet-enabled televisions, a huge variety of mobile devices, and dozens of other ways. Not all of these devices are capable of executing JavaScript, and some of them don't even have color screens! Your number one priority should be making sure that your content is available to anyone who asks for it, no matter what device they happen to be using.

Gotta keep 'em separated

To accomplish this task of making our content available to as wide an audience as possible, we have to think of our web pages in three separate and distinct layers: content, presentation, and behavior.

Content

Content is the meat of our web page. It's the text or audio or video content that we're most interested in presenting on our page; so this is where we start.

Mark up your content with clean and simple HTML code. Use HTML elements the way they were intended to be used. Mark up headings with heading tags, paragraphs with paragraph tags, lists with list tags, and save tables for tabular data.

Browsers have built-in styles for these basic HTML tags—headings will be of a larger type and will probably look bold. Lists will have bullets or numbers. It might not look very fancy, but it's readable and accessible to anyone.

Presentation

The presentation layer is where we start to get fancy. This is where we introduce CSS and start applying our own styles to the content we've created. As we style our page, we might find that we have to go back into our HTML code and add some new containers and markup to make things such as multicolumn layouts possible, but we should still strive to keep our markup as simple and as straightforward as we can.

Behavior

Once our page has all of our content properly marked up and is styled to look the way we like, we can think about adding in some interactive behavior. This is where JavaScript and jQuery come in. This layer includes animations, special effects, AJAX, and so on.