
jQuery Cookbook
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
More details
Other editions
Additional editions

Content
- Intro
- Table of Contents
- Foreword
- Contributors
- Chapter Authors
- Tech Editors
- Preface
- Who This Book Is For
- What You'll Learn
- jQuery Style and Conventions
- Other Options
- If You Have Problems Making Examples Work
- If You Like (or Don't Like) This Book
- Conventions Used in This Book
- Using Code Examples
- Safari® Books Online
- How to Contact Us
- Chapter 1. jQuery Basics
- 1.0 Introduction
- Why jQuery?
- The jQuery Philosophy
- Find some elements and do something with them
- Chaining
- The jQuery wrapper set
- How the jQuery API Is Organized
- 1.1 Including the jQuery Library Code in an HTML Page
- Problem
- Solution
- Discussion
- 1.2 Executing jQuery/JavaScript Coded After the DOM Has Loaded but Before Complete Page Load
- Problem
- Solution
- Discussion
- 1.3 Selecting DOM Elements Using Selectors and the jQuery Function
- Problem
- Solution
- Discussion
- 1.4 Selecting DOM Elements Within a Specified Context
- Problem
- Solution
- Discussion
- 1.5 Filtering a Wrapper Set of DOM Elements
- Problem
- Solution
- Discussion
- 1.6 Finding Descendant Elements Within the Currently Selected Wrapper Set
- Problem
- Solution
- Discussion
- 1.7 Returning to the Prior Selection Before a Destructive Change
- Problem
- Solution
- Discussion
- 1.8 Including the Previous Selection with the Current Selection
- Problem
- Solution
- Discussion
- 1.9 Traversing the DOM Based on Your Current Context to Acquire a New Set of DOM Elements
- Problem
- Solution
- Discussion
- 1.10 Creating, Operating on, and Inserting DOM Elements
- Problem
- Solution
- Discussion
- 1.11 Removing DOM Elements
- Problem
- Solution
- Discussion
- 1.12 Replacing DOM Elements
- Problem
- Solution
- Discussion
- 1.13 Cloning DOM Elements
- Problem
- Solution
- Discussion
- 1.14 Getting, Setting, and Removing DOM Element Attributes
- Problem
- Solution
- Discussion
- 1.15 Getting and Setting HTML Content
- Problem
- Solution
- Discussion
- 1.16 Getting and Setting Text Content
- Problem
- Solution
- Discussion
- 1.17 Using the $ Alias Without Creating Global Conflicts
- Problem
- Solution
- Discussion
- Chapter 2. Selecting Elements with jQuery
- 2.0 Introduction
- 2.1 Selecting Child Elements Only
- Problem
- Solution
- Discussion
- 2.2 Selecting Specific Siblings
- Problem
- Solution
- Discussion
- 2.3 Selecting Elements by Index Order
- Problem
- Solution
- Discussion
- 2.4 Selecting Elements That Are Currently Animating
- Problem
- Solution
- Discussion
- 2.5 Selecting Elements Based on What They Contain
- Problem
- Solution
- Discussion
- 2.6 Selecting Elements by What They Don't Match
- Problem
- Solution
- Discussion
- 2.7 Selecting Elements Based on Their Visibility
- Problem
- Solution
- Discussion
- 2.8 Selecting Elements Based on Attributes
- Problem
- Solution
- Discussion
- 2.9 Selecting Form Elements by Type
- Problem
- Solution
- Discussion
- 2.10 Selecting an Element with Specific Characteristics
- Problem
- Solution
- Discussion
- 2.11 Using the Context Parameter
- Problem
- Solution
- Discussion
- 2.12 Creating a Custom Filter Selector
- Problem
- Solution
- Discussion
- Chapter 3. Beyond the Basics
- 3.0 Introduction
- 3.1 Looping Through a Set of Selected Results
- Problem
- Solution
- Discussion
- 3.2 Reducing the Selection Set to a Specified Item
- Problem
- Solution
- Discussion
- 3.3 Convert a Selected jQuery Object into a Raw DOM Object
- Problem
- Solution
- Discussion
- 3.4 Getting the Index of an Item in a Selection
- Problem
- Solution
- Discussion
- 3.5 Making a Unique Array of Values from an Existing Array
- Problem
- Solution
- Discussion
- 3.6 Performing an Action on a Subset of the Selected Set
- Problem
- Solution
- Discussion
- 3.7 Configuring jQuery Not to Conflict with Other Libraries
- Problem
- Solution
- Discussion
- 3.8 Adding Functionality with Plugins
- Problem
- Solution
- Discussion
- 3.9 Determining the Exact Query That Was Used
- Problem
- Solution
- Discussion
- Chapter 4. jQuery Utilities
- 4.0 Introduction
- 4.1 Detecting Features with jQuery.support
- Problem
- Solution
- Discussion
- 4.2 Iterating Over Arrays and Objects with jQuery.each
- Problem
- Solution
- Discussion
- 4.3 Filtering Arrays with jQuery.grep
- Problem
- Solution
- Discussion
- 4.4 Iterating and Modifying Array Entries with jQuery.map
- Problem
- Solution
- Discussion
- 4.5 Combining Two Arrays with jQuery.merge
- Problem
- Solution
- Discussion
- 4.6 Filtering Out Duplicate Array Entries with jQuery.unique
- Problem
- Solution
- Discussion
- 4.7 Testing Callback Functions with jQuery.isFunction
- Problem
- Solution
- Discussion
- 4.8 Removing Whitespace from Strings or Form Values with jQuery.trim
- Problem
- Solution
- Discussion
- 4.9 Attaching Objects and Data to DOM with jQuery.data
- Problem
- Solution
- Discussion
- 4.10 Extending Objects with jQuery.extend
- Problem
- Solution
- Discussion
- Chapter 5. Faster, Simpler, More Fun
- 5.0 Introduction
- 5.1 That's Not jQuery, It's JavaScript!
- Problem
- Solution
- Discussion
- 5.2 What's Wrong with $(this)?
- Problem
- Solution
- Discussion
- 5.3 Removing Redundant Repetition
- Problem
- Solution 1
- Solution 2
- Discussion
- 5.4 Formatting Your jQuery Chains
- Problem
- Solution
- Discussion
- 5.5 Borrowing Code from Other Libraries
- Problem
- Solution
- Discussion
- 5.6 Writing a Custom Iterator
- Problem
- Solution
- Discussion
- 5.7 Toggling an Attribute
- Problem
- Solution
- Discussion
- 5.8 Finding the Bottlenecks
- Problem
- Solution
- Discussion
- 5.9 Caching Your jQuery Objects
- Problem
- Solution
- Discussion
- 5.10 Writing Faster Selectors
- Problem
- Solution
- Discussion
- 5.11 Loading Tables Faster
- Problem
- Solution
- Discussion
- 5.12 Coding Bare-Metal Loops
- Problem
- Solution
- Discussion
- 5.13 Reducing Name Lookups
- Problem
- Solution
- Discussion
- 5.14 Updating the DOM Faster with .innerHTML
- Problem
- Solution
- Discussion
- 5.15 Debugging? Break Those Chains
- Problem
- Solution
- Discussion
- 5.16 Is It a jQuery Bug?
- Problem
- Solution
- Discussion
- 5.17 Tracing into jQuery
- Problem 1
- Solution 1
- Problem 2
- Solution 2
- Discussion
- 5.18 Making Fewer Server Requests
- Problem
- Solution
- Discussion
- 5.19 Writing Unobtrusive JavaScript
- Problem
- Solution
- Discussion
- 5.20 Using jQuery for Progressive Enhancement
- Problem
- Solution
- Discussion
- 5.21 Making Your Pages Accessible
- Problem
- Solution
- Discussion
- Chapter 6. Dimensions
- 6.0 Introduction
- 6.1 Finding the Dimensions of the Window and Document
- Problem
- Solution
- Discussion
- 6.2 Finding the Dimensions of an Element
- Problem
- Solution
- Discussion
- 6.3 Finding the Offset of an Element
- Problem
- Solution
- Discussion
- 6.4 Scrolling an Element into View
- Problem
- Solution: Scrolling the Whole Window
- Solution: Scrolling Inside an Element
- 6.5 Determining Whether an Element Is Within the Viewport
- Problem
- Solution
- 6.6 Centering an Element Within the Viewport
- Problem
- Solution
- 6.7 Absolutely Positioning an Element at Its Current Position
- Problem
- Solution
- 6.8 Positioning an Element Relative to Another Element
- Problem
- Solution
- 6.9 Switching Stylesheets Based on Browser Width
- Problem
- Solutions
- Solution 1: Changing the Class on the Body Element
- Solution 2: Changing the href Attribute of the Stylesheet That's Responsible for Size-Related Styling
- Solution 3: Include All Size-Related Stylesheets in the Page, but Enable Only One at a Time
- Discussion
- Chapter 7. Effects
- 7.0 Introduction
- Animate Method
- Animation Speeds
- Effects Template
- 7.1 Sliding and Fading Elements in and out of View
- Problem
- Solution
- Slide
- Fade
- Both
- Discussion
- 7.2 Making Elements Visible by Sliding Them Up
- Problem
- Solution
- HTML
- CSS
- jQuery
- Discussion
- 7.3 Creating a Horizontal Accordion
- Problem
- Solution
- HTML
- CSS
- jQuery
- Discussion
- 7.4 Simultaneously Sliding and Fading Elements
- Solution
- Discussion
- 7.5 Applying Sequential Effects
- Problem
- Solution
- Manual callback
- Automatic sequence
- Discussion
- 7.6 Determining Whether Elements Are Currently Being Animated
- Problem
- Solution
- Discussion
- 7.7 Stopping and Resetting Animations
- Problem
- Solution
- Discussion
- 7.8 Using Custom Easing Methods for Effects
- Problem
- Solution
- Discussion
- 7.9 Disabling All Effects
- Problem
- Solution
- Discussion
- 7.10 Using jQuery UI for Advanced Effects
- Problem
- Solution
- CSS
- jQuery
- Discussion
- Chapter 8. Events
- 8.0 Introduction
- 8.1 Attaching a Handler to Many Events
- Problem
- Solution
- Discussion
- 8.2 Reusing a Handler Function with Different Data
- Problem
- Solution
- Discussion
- 8.3 Removing a Whole Set of Event Handlers
- Problem
- Solution
- Discussion
- How to bind with a namespace?
- How to clean up my plugin?
- 8.4 Triggering Specific Event Handlers
- Problem
- Solution
- Discussion
- How to trigger handlers with a certain namespace?
- How to trigger handlers that do not have a namespace?
- 8.5 Passing Dynamic Data to Event Handlers
- Problem
- Solution
- Discussion
- Passing extra arguments
- Passing a custom event object
- Some more examples
- What's the difference with event.data?
- 8.6 Accessing an Element ASAP (Before document.ready)
- Problem
- Solution
- Discussion
- Hide an element right away (or another style operation)
- Bind event handlers to an element ASAP
- Any other situation
- Polling
- Customly positioned scripts
- 8.7 Stopping the Handler Execution Loop
- Problem
- Solution
- Discussion
- Examples
- Simple form validation
- Disadvantages of this approach
- Killing all events
- 8.8 Getting the Correct Element When Using event.target
- Problem
- Solution
- Discussion
- 8.9 Avoid Multiple hover() Animations in Parallel
- Problem
- Solution
- Discussion
- Example
- Not there yet
- 8.10 Making Event Handlers Work for Newly Added Elements
- Problem
- Solution
- Discussion
- Why do event handlers get lost ?
- A little introduction to event delegation
- Pros and cons of each approach
- Rebinding
- Event delegation
- Conclusion
- Chapter 9. Advanced Events
- 9.0 Introduction
- 9.1 Getting jQuery to Work When Loaded Dynamically
- Problem
- Solution
- Discussion
- What is jQuery.ready()?
- Why was this happening?
- 9.2 Speeding Up Global Event Triggering
- Problem
- Solution
- Discussion
- Pros and cons
- Making the listeners functional
- 9.3 Creating Your Own Events
- Problem
- Solution
- Discussion
- Handling every binding to your event
- A real-world example
- Existing uses for this feature
- 9.4 Letting Event Handlers Provide Needed Data
- Problem
- Solution
- Discussion
- How can we do this with jQuery 1.3+?
- How this was achieved before jQuery 1.3
- Allowing event handlers to prevent actions
- 9.5 Creating Event-Driven Plugins
- Problem
- Solution
- Discussion
- An example
- What happens if an element already has one of these events?
- How can I allow others to clean up the added event handlers?
- What's the difference with other approaches?
- Allowing the plugin to accept commands
- Returning an object with methods
- 9.6 Getting Notified When jQuery Methods Are Called
- Problem
- Solution
- Discussion
- Overloading the desired method
- Triggering an event prior to the execution
- Executing the original method
- Triggering an event after the execution
- Returning the result
- Putting it all together
- Where to go from here?
- 9.7 Using Objects' Methods as Event Listeners
- Problem
- Solution
- Discussion
- Where did the node go?
- The example
- The objects
- Binding the methods
- Chapter 10. HTML Form Enhancements from Scratch
- 10.0 Introduction
- 10.1 Focusing a Text Input on Page Load
- Problem
- Solution
- Discussion
- 10.2 Disabling and Enabling Form Elements
- Problem
- Solution 1
- Solution 2
- Discussion
- 10.3 Selecting Radio Buttons Automatically
- Problem
- Solution 1
- Solution 2
- Discussion
- 10.4 (De)selecting All Checkboxes Using Dedicated Links
- Problem
- Solution
- Discussion
- 10.5 (De)selecting All Checkboxes Using a Single Toggle
- Problem
- Solution
- Discussion
- 10.6 Adding and Removing Select Options
- Problem
- Solution
- Discussion
- 10.7 Autotabbing Based on Character Count
- Problem
- Solution
- Discussion
- 10.8 Displaying Remaining Character Count
- Problem
- Solution
- Discussion
- 10.9 Constraining Text Input to Specific Characters
- Problem
- Solution
- Discussion
- 10.10 Submitting a Form Using Ajax
- Problem
- Solution
- Discussion
- 10.11 Validating Forms
- Problem
- Solution
- Discussion
- Chapter 11. HTML Form Enhancements with Plugins
- 11.0 Introduction
- Basic Approach
- 11.1 Validating Forms
- Problem
- Solution
- Discussion
- Methods
- Custom methods
- Rules
- Error messages
- Dependencies
- Custom expressions
- Localization
- Error element
- Layout
- Handling the submit
- Limitations
- 11.2 Creating Masked Input Fields
- Problem
- Solution
- Discussion
- Limitations
- 11.3 Autocompleting Text Fields
- Problem
- Solution
- Discussion
- 11.4 Selecting a Range of Values
- Problem
- Solution
- Discussion
- 11.5 Entering a Range-Constrained Value
- Problem
- Solution
- Discussion
- Google Maps integration
- 11.6 Uploading Files in the Background
- Problem
- Solution
- Discussion
- 11.7 Limiting the Length of Text Inputs
- Problem
- Solution
- Discussion
- 11.8 Displaying Labels Above Input Fields
- Problem
- Solution
- Discussion
- 11.9 Growing an Input with Its Content
- Problem
- Solution
- Discussion
- 11.10 Choosing a Date
- Problem
- Solution
- Discussion
- Localization
- Chapter 12. jQuery Plugins
- 12.0 Introduction
- 12.1 Where Do You Find jQuery Plugins?
- Problem
- Solution
- Discussion
- Search through the jQuery Plugin Repository
- Search through Google Code
- Search through GitHub
- Perform a Google search
- Search through SourceForge
- 12.2 When Should You Write a jQuery Plugin?
- Problem
- Solution
- Discussion
- Build a plugin if there is a potential audience
- Know and communicate the level of support you are willing to provide
- Plan for participation from others
- 12.3 Writing Your First jQuery Plugin
- Problem
- Solution
- Writing a custom jQuery method
- Writing a custom jQuery function
- Discussion
- 12.4 Passing Options into Your Plugin
- Problem
- Solution
- Discussion
- 12.5 Using the $ Shortcut in Your Plugin
- Problem
- Solution
- Discussion
- 12.6 Including Private Functions in Your Plugin
- Problem
- Solution
- Discussion
- 12.7 Supporting the Metadata Plugin
- Problem
- Solution
- Discussion
- 12.8 Adding a Static Function to Your Plugin
- Problem
- Solution
- Discussion
- 12.9 Unit Testing Your Plugin with QUnit
- Problem
- Solution
- Discussion
- Chapter 13. Interface Components from Scratch
- 13.0 Introduction
- 13.1 Creating Custom Tool Tips
- Problem
- Solution
- Tool tip-HTML code
- Tool tip-jQuery code
- Discussion
- 13.2 Navigating with a File-Tree Expander
- Problem
- Solution
- File tree-HTML code
- File tree-jQuery code
- Discussion
- 13.3 Expanding an Accordion
- Problem
- Solution
- Accordion-HTML code
- Accordion-jQuery code
- Discussion
- 13.4 Tabbing Through a Document
- Problem
- Solution
- Tabs-HTML code
- Tabs-jQuery code
- Discussion
- 13.5 Displaying a Simple Modal Window
- Problem
- Solution
- Modal-HTML code
- Modal-jQuery code
- Discussion
- 13.6 Building Drop-Down Menus
- Problem
- Solution
- Drop-down-HTML code
- Drop-down-jQuery code
- Discussion
- 13.7 Cross-Fading Rotating Images
- Problem
- Solution
- Rotator-HTML code
- Rotator-jQuery code
- Discussion
- 13.8 Sliding Panels
- Problem
- Solution
- Panels-HTML code
- Panels-jQuery code
- Discussion
- Chapter 14. User Interfaces with jQuery UI
- 14.0 Introduction
- Interactions
- Widgets
- Effects
- Basic Usage
- How This Chapter Is Organized
- 14.1 Including the Entire jQuery UI Suite
- Problem
- Solution
- Discussion
- 14.2 Including an Individual jQuery UI Plugin or Two
- Problem
- Solution
- Discussion
- 14.3 Initializing a jQuery UI Plugin with Default Options
- Problem
- Solution
- Discussion
- 14.4 Initializing a jQuery UI Plugin with Custom Options
- Problem
- Solution
- Discussion
- 14.5 Creating Your Very Own jQuery UI Plugin Defaults
- Problem
- Solution
- Discussion
- 14.6 Getting and Setting jQuery UI Plugin Options
- Problem
- Solution 1: Getting the Value
- Solution 2: Setting the Value
- Discussion
- 14.7 Calling jQuery UI Plugin Methods
- Problem
- Solution
- Discussion
- 14.8 Handling jQuery UI Plugin Events
- Problem
- Solution 1: Pass a Callback Function to the Event Name Option
- Solution 2: Bind to the Custom Event Using the Event Type
- Discussion
- 14.9 Destroying a jQuery UI Plugin
- Problem
- Solution
- Discussion
- 14.10 Creating a jQuery UI Music Player
- Problem
- Solution
- HTML5 audio
- The music player
- Play and pause button
- Current and total time labels
- Slider track for song position
- Progress bar in track to show buffering
- Volume slider
- Widget background and top styling
- Chapter 15. jQuery UI Theming
- 15.0 Introduction
- Understanding the Components of jQuery UI CSS
- 15.1 Styling jQuery UI Widgets with ThemeRoller
- Problem
- Solution
- Step 1. Open ThemeRoller
- Step 2. Create and preview a theme
- Step 3. Download the jQuery UI widgets and theme
- Step 4. Merge files into your project directory
- Step 5. Reference the theme stylesheet in your project
- Discussion
- 15.2 Overriding jQuery UI Layout and Theme Styles
- Problem
- Solution
- Step 1. Review the widget markup and styles for jQuery UI plugins
- Step 2. Create an override stylesheet
- Step 3. Edit the style rules in your override stylesheet
- Scope overrides
- Write override rules
- Discussion
- 15.3 Applying a Theme to Non-jQuery UI Components
- Problem
- Solution
- Step 1: Review available Framework classes to identify those you can apply to your components
- Step 2: Apply clickable-state Framework classes
- Discussion
- 15.4 Referencing Multiple Themes on a Single Page
- Problem
- Solution
- Step 1. Create another theme using ThemeRoller
- Step 2. Scope the new theme and download it
- Step 3. Merge files into your project directory
- Step 4. Reference the scoped theme stylesheet in your project
- 15.5 Appendix: Additional CSS Resources
- Chapter 16. jQuery, Ajax, Data Formats: HTML, XML, JSON, JSONP
- 16.0 Introduction
- 16.1 jQuery and Ajax
- Problem
- Solution
- Discussion
- 16.2 Using Ajax on Your Whole Site
- Problem
- Solution
- Discussion
- 16.3 Using Simple Ajax with User Feedback
- Problem
- Solution
- Discussion
- 16.4 Using Ajax Shortcuts and Data Types
- Problem
- Solution
- Discussion
- 16.5 Using HTML Fragments and jQuery
- Problem
- Solution
- Discussion
- 16.6 Converting XML to DOM
- Problem
- Solution
- Discussion
- 16.7 Creating JSON
- Problem
- Solution
- Discussion
- 16.8 Parsing JSON
- Problem
- Solution
- Discussion
- 16.9 Using jQuery and JSONP
- Problem
- Solution
- Discussion
- Chapter 17. Using jQuery in Large Projects
- 17.0 Introduction
- 17.1 Using Client-Side Storage
- Problem
- Solution
- Discussion
- 17.2 Saving Application State for a Single Session
- Problem
- Solution
- Discussion
- 17.3 Saving Application State Between Sessions
- Problem
- Solution
- Discussion
- 17.4 Using a JavaScript Template Engine
- Problem
- Solution
- Discussion
- 17.5 Queuing Ajax Requests
- Problem
- Solution
- Discussion
- 17.6 Dealing with Ajax and the Back Button
- Problem
- Solution
- Discussion
- 17.7 Putting JavaScript at the End of a Page
- Problem
- Solution
- Discussion
- Chapter 18. Unit Testing
- 18.0 Introduction
- 18.1 Automating Unit Testing
- Problem
- Solution
- Discussion
- 18.2 Asserting Results
- Problem
- Solution
- ok( boolean[, message ])
- equals( actual, expected[, message ])
- same( actual, expected[, message ])
- 18.3 Testing Synchronous Callbacks
- Problem
- Solution
- Discussion
- 18.4 Testing Asynchronous Callbacks
- Problem
- Solution
- Discussion
- 18.5 Testing User Actions
- Problem
- Solution
- Discussion
- 18.6 Keeping Tests Atomic
- Problem
- Solution
- Discussion
- 18.7 Grouping Tests
- Problem
- Solution
- Discussion
- 18.8 Selecting Tests to Run
- Problem
- Solution
- Discussion
- Index
System requirements
File format: PDF
Copy-Protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (only limited: Kindle).
The file format PDF always displays a book page identically on any hardware. This makes PDF suitable for complex layouts such as those used in textbooks and reference books (images, tables, columns, footnotes). Unfortunately, on the small screens of e-readers or smartphones, PDFs are rather annoying, requiring too much scrolling.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our eBook Help page.