JavaScript & jQuery: The Missing Manual, 2nd Edition

Book description

JavaScript lets you supercharge your web pages with animation, interactivity, and visual effects, but learning the language isn’t easy. This fully updated and expanded guide takes you step-by-step through JavaScript basics, then shows you how to save time and effort with jQuery—the library of prewritten JavaScript code—and the newest innovations from the jQuery UI plug-in.

The important stuff you need to know:

  • Make your pages come alive. Use jQuery to create interactive elements that respond to visitor input.
  • Get acquainted with jQuery UI. Expand your interface with tabbed panels, dialog boxes, date pickers, and other widgets.
  • Display good forms. Get information from visitors, help shoppers buy goods, and let members post their thoughts.
  • Go beyond the browser with Ajax. Communicate with the web server to update your pages without reloading.
  • Put your new skills right to work. Create a simple application step-by-step, using jQuery and jQuery UI widgets.
  • Dive into advanced concepts. Use ThemeRoller to customize your widgets; avoid common errors that new programmers often make.

Publisher resources

View/Submit Errata

Table of contents

  1. A Note Regarding Supplemental Files
  2. The Missing Credits
    1. About the Author
    2. About the Creative Team
    3. Acknowledgements
    4. The Missing Manual Series
  3. Introduction
    1. What Is JavaScript?
      1. A Bit of History
      2. JavaScript Is Everywhere
    2. What Is jQuery?
    3. HTML: The Barebones Structure
      1. How HTML Tags Work
    4. CSS: Adding Style to Web Pages
      1. Anatomy of a Style
    5. Software for JavaScript Programming
      1. Free Programs
      2. Commercial Software
    6. About This Book
      1. This Book’s Approach to JavaScript
      2. About the Outline
    7. The Very Basics
      1. About→These→Arrows
    8. About the Online Resources
      1. Living Examples
      2. Registration
      3. Feedback
      4. Errata
      5. Safari® Books Online
  4. One. Getting Started with JavaScript
    1. 1. Writing Your First JavaScript Program
      1. Introducing Programming
        1. What’s a Computer Program?
      2. How to Add JavaScript to a Page
        1. External JavaScript Files
      3. Your First JavaScript Program
      4. Writing Text on a Web Page
      5. Attaching an External JavaScript File
      6. Tracking Down Errors
        1. The Firefox JavaScript Console
        2. Displaying the Internet Explorer 9 Console
        3. Opening the Chrome JavaScript Console
        4. Accessing the Safari Error Console
    2. 2. The Grammar of JavaScript
      1. Statements
      2. Built-In Functions
      3. Types of Data
        1. Numbers
        2. Strings
        3. Booleans
      4. Variables
        1. Creating a Variable
        2. Using Variables
      5. Working with Data Types and Variables
        1. Basic Math
        2. The Order of Operations
        3. Combining Strings
        4. Combining Numbers and Strings
        5. Changing the Values in Variables
      6. Tutorial: Using Variables to Create Messages
      7. Tutorial: Asking for Information
      8. Arrays
        1. Creating an Array
        2. Accessing Items in an Array
        3. Adding Items to an Array
          1. Adding an item to the end of an array
          2. Adding an item to the beginning of an array
          3. Choosing how to add items to an array
        4. Deleting Items from an Array
      9. Tutorial: Writing to a Web Page Using Arrays
      10. A Quick Object Lesson
      11. Comments
        1. When to Use Comments
        2. Comments in This Book
    3. 3. Adding Logic and Control to Your Programs
      1. Making Programs React Intelligently
        1. Conditional Statement Basics
        2. Adding a Backup Plan
        3. Testing More Than One Condition
        4. More Complex Conditions
          1. Making sure more than one condition is true
          2. Making sure at least one condition is true
          3. Negating a condition
        5. Nesting Conditional Statements
        6. Tips for Writing Conditional Statements
      2. Tutorial: Using Conditional Statements
      3. Handling Repetitive Tasks with Loops
        1. While Loops
        2. Loops and Arrays
        3. For Loops
        4. Do/While Loops
      4. Functions: Turn Useful Code Into Reusable Commands
        1. Mini-Tutorial
        2. Giving Information to Your Functions
        3. Retrieving Information from Functions
        4. Keeping Variables from Colliding
      5. Tutorial: A Simple Quiz
  5. Two. Getting Started with jQuery
    1. 4. Introducing jQuery
      1. About JavaScript Libraries
      2. Getting jQuery
        1. Linking to the jQuery file on a CDN server
          1. Linking to the jQuery file on a CDN server
          2. Downloading your own jQuery file
      3. Adding jQuery to a Page
      4. Modifying Web Pages: An Overview
      5. Understanding the Document Object Model
      6. Selecting Page Elements: The jQuery Way
        1. Basic Selectors
          1. ID selectors
          2. Element selectors
          3. Class selectors
        2. Advanced Selectors
        3. jQuery Filters
        4. Understanding jQuery Selections
          1. Automatic loops
          2. Chaining functions
      7. Adding Content to a Page
        1. Replacing and Removing Selections
      8. Setting and Reading Tag Attributes
        1. Classes
        2. Reading and Changing CSS Properties
        3. Changing Multiple CSS Properties at Once
      9. Reading, Setting, and Removing HTML Attributes
      10. Acting on Each Element in a Selection
        1. Anonymous Functions
        2. this and $(this)
      11. Automatic Pull Quotes
        1. Overview
        2. Programming
    2. 5. Action/Reaction: Making Pages Come Alive with Events
      1. What Are Events?
        1. Mouse Events
        2. Document/Window Events
        3. Form Events
        4. Keyboard Events
      2. Using Events the jQuery Way
      3. Tutorial: Introducing Events
      4. More jQuery Event Concepts
        1. Waiting for the HTML to Load
        2. jQuery Events
          1. The hover() event
          2. The toggle() Event
        3. The Event Object
        4. Stopping an Event’s Normal Behavior
        5. Removing Events
      5. Advanced Event Management
        1. Other Ways to Use the bind() Function
      6. Tutorial: A One-Page FAQ
        1. Overview of the Task
        2. The Programming
    3. 6. Animations and Effects
      1. jQuery Effects
        1. Basic Showing and Hiding
        2. Fading Elements In and Out
        3. Sliding Elements
      2. Tutorial: Login Slider
        1. The Programming
      3. Animations
        1. Easing
      4. Performing an Action After an Effect Is Completed
      5. Tutorial: Animated Dashboard
        1. The Programming
  6. Three. Building Web Page Features
    1. 7. Improving Your Images
      1. Swapping Images
        1. Changing an Image’s src Attribute
        2. Preloading Images
        3. Rollover Images
      2. Tutorial: Adding Rollover Images
        1. Overview of the Task
        2. The Programming
      3. Tutorial: Photo Gallery with Effects
        1. Overview of Task
        2. The Programming
      4. Advanced Gallery with jQuery FancyBox
        1. The Basics
        2. Creating a Gallery of Images
        3. Customizing FancyBox
          1. FancyBox options
          2. Styling FancyBox
      5. Tutorial: FancyBox Photo Gallery
    2. 8. Improving Navigation
      1. Some Link Basics
        1. Selecting Links with JavaScript
        2. Determining a Link’s Destination
        3. Don’t Follow That Link
      2. Opening External Links in a New Window
      3. Creating New Windows
        1. Window Properties
          1. Use the window reference
          2. Events that can open a new window
      4. Opening Pages in a Window on the Page
        1. Tutorial: Opening a Page Within a Page
      5. Basic, Animated Navigation Bar
        1. The HTML
        2. The CSS
        3. The JavaScript
        4. The Tutorial
    3. 9. Enhancing Web Forms
      1. Understanding Forms
        1. Selecting Form Elements
        2. Getting and Setting the Value of a Form Element
        3. Determining Whether Buttons and Boxes Are Checked
        4. Form Events
          1. Submit
          2. Focus
          3. Blur
          4. Click
          5. Change
      2. Adding Smarts to Your Forms
        1. Focusing the First Field in a Form
        2. Disabling and Enabling Fields
        3. Hiding and Showing Form Options
      3. Tutorial: Basic Form Enhancements
        1. Focusing a Field
        2. Disabling Form Fields
        3. Hiding Form Fields
      4. Form Validation
        1. jQuery Validation Plug-in
        2. Basic Validation
          1. Adding validation rules
          2. Adding error messages
        3. Advanced Validation
          1. Advanced rules
          2. Advanced error messages
        4. Styling Error Messages
      5. Validation Tutorial
        1. Basic Validation
        2. Advanced Validation
        3. Validating Checkboxes and Radio Buttons
        4. Formatting the Error Messages
    4. 10. Expanding Your Interface
      1. Organizing Information in Tabbed Panels
        1. The HTML
        2. The CSS
        3. The JavaScript
        4. Tabbed Panels Tutorial
      2. Adding a Content Slider to Your Site
        1. Using AnythingSlider
        2. AnythingSlider Tutorial
        3. Customizing the Slider Appearance
        4. Customizing the Slider Behavior
      3. Determining the Size and Position of Page Elements
        1. Determining the Height and Width of Elements
        2. Determining the Position of Elements on a Page
        3. Determining a Page’s Scrolling Position
      4. Adding Tooltips
        1. The HTML
        2. The CSS
        3. The JavaScript
        4. Tooltips Tutorial
  7. Four. Ajax: Communication with the Web Server
    1. 11. Introducing Ajax
      1. What Is Ajax?
      2. Ajax: The Basics
        1. Pieces of the Puzzle
        2. Talking to the Web Server
      3. Ajax the jQuery Way
        1. Using the load() Function
        2. Tutorial: The load() Function
          1. Overview
          2. The programming
        3. The get() and post() Functions
        4. Formatting Data to Send to the Server
          1. Query string
          2. Object literal
          3. jQuery’s serialize() function
        5. Processing Data from the Server
        6. Handling Errors
        7. Tutorial: Using the get() Function
          1. Overview
          2. The programming
      4. JSON
        1. Accessing JSON Data
        2. Complex JSON Objects
    2. 12. Flickr and Google Maps
      1. Introducing JSONP
      2. Adding a Flickr Feed to Your Site
        1. Constructing the URL
          1. A few other options for the public photos feed
        2. Using the $.getJSON() Function
        3. Understanding the Flickr JSON Feed
      3. Tutorial: Adding Flickr Images to Your Site
      4. Adding Google Maps to Your Site
        1. Setting a Location for the Map
        2. Other GoMap Options
        3. Adding Markers
        4. Adding Information Windows to Markers
        5. GoMap Tutorial
  8. Five. Tips, Tricks, and Troubleshooting
    1. 13. Getting the Most from jQuery
      1. Useful jQuery Tips and Information
        1. $() Is the Same as jQuery()
        2. Saving Selections Into Variables
        3. Adding Content as Few Times as Possible
        4. Optimizing Your Selectors
      2. Using the jQuery Docs
        1. Reading a Page on the jQuery Docs Site
      3. Traversing the DOM
      4. More Functions For Manipulating HTML
      5. Advanced Event Handling
    2. 14. Going Further with JavaScript
      1. Working with Strings
        1. Determining the Length of a String
        2. Changing the Case of a String
        3. Searching a String: indexOf() Technique
        4. Extracting Part of a String with slice()
      2. Finding Patterns in Strings
        1. Creating and Using a Basic Regular Expression
        2. Building a Regular Expression
        3. Grouping Parts of a Pattern
        4. Useful Regular Expressions
          1. U.S. Zip code
          2. U.S. phone number
          3. Email address
          4. Date
          5. Web address
        5. Matching a Pattern
          1. Matching every instance of a pattern
        6. Replacing Text
        7. Trying Out Regular Expressions
      3. Working with Numbers
        1. Changing a String to a Number
        2. Testing for Numbers
        3. Rounding Numbers
        4. Formatting Currency Values
        5. Creating a Random Number
          1. Randomly selecting an array element
          2. A function for selecting a random number
      4. Dates and Times
        1. Getting the Month
        2. Getting the Day of the Week
        3. Getting the Time
          1. Changing hours to a.m. and p.m.
          2. Padding single digits
        4. Creating a Date Other Than Today
          1. Creating a date that’s one week from today
      5. Putting It All Together
        1. Using External JavaScript Files
      6. Writing More Efficient JavaScript
        1. Putting Preferences in Variables
        2. Ternary Operator
        3. The Switch Statement
      7. Creating Fast-Loading JavaScript
    3. 15. Troubleshooting and Debugging
      1. Top JavaScript Programming Mistakes
        1. Non-Closed Pairs
        2. Quotation Marks
        3. Using Reserved Words
        4. Single Equals in Conditional Statements
        5. Case-Sensitivity
        6. Incorrect Path to External JavaScript File
        7. Incorrect Paths Within External JavaScript Files
        8. Disappearing Variables and Functions
      2. Debugging with Firebug
        1. Installing and Turning On Firebug
        2. Viewing Errors with Firebug
        3. Using console.log() to Track Script Progress
        4. Tutorial: Using the Firebug Console
        5. More Powerful Debugging
          1. Controlling your script with the debugger
          2. Watching your script
      3. Debugging Tutorial
    4. A. JavaScript Resources
      1. References
        1. Websites
        2. Books
      2. Basic JavaScript
        1. Articles and Presentations
        2. Websites
        3. Books
      3. jQuery
        1. Articles and Presentations
        2. Websites
        3. Books
      4. Ajax
        1. Websites
        2. Books
      5. Advanced JavaScript
        1. Articles and Presentations
        2. Websites
        3. Books
      6. CSS
        1. Websites
        2. Books
  9. Index
  10. About the Author
  11. Colophon
  12. Copyright

Product information

  • Title: JavaScript & jQuery: The Missing Manual, 2nd Edition
  • Author(s): David Sawyer McFarland
  • Release date: October 2011
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449399023