jQuery and JavaScript Phrasebook

Book description

Get more done faster with jQuery and JavaScript! Brad Dayley’s jQuery and JavaScript Phrasebook brings together 100+ instantly useful code snippets and idioms for performing a wide spectrum of common web application tasks. This hands-on guide gets straight to the essence of what’s new and important in jQuery and JavaScript, and what you need to know to build new web solutions or migrate existing sites to jQuery.

Building on JavaScript Phrasebook, Dayley presents carefully tested, flexible, adaptable code - all organized for quick lookup and easy use. Dayley’s coverage ranges from the basics to advanced jQuery capabilities, including jQueryUI widgets and mobile development. Coverage includes:

  • Basics, including selecting and manipulating HTML elements with jQuery Selector

  • Dynamically manipulating CSS values

  • Handling browser and DOM events

  • Performing validation

  • Server communication

  • REST, PHP, MySQL, AJAX, and JSON/XML data

  • Positioning web page elements and making them interactive

  • Using animation and other special effects

  • And much more

jQuery and JavaScript Phrasebook is the perfect quick reference for millions of web developers who want reliable solutions they can use right now -- with no distractions and no diversions!

Table of contents

  1. About This eBook
  2. Title Page
  3. Copyright Page
  4. Dedication
  5. Contents
  6. Acknowledgments
  7. About the Author
  8. We Want to Hear from You!
  9. Reader Services
  10. 1. Jumping into jQuery, JavaScript, and the World of Dynamic Web Development
    1. Understanding JavaScript
      1. Adding JavaScript to an HTML Document
      2. Loading JavaScript from External Files
    2. Introducing jQuery
      1. Loading jQuery in Your Web Pages
      2. Accessing jQuery in Your JavaScript
    3. Introducing jQuery UI
      1. Getting the jQuery UI Library
      2. Loading jQuery UI
    4. Introducing jQuery Mobile
      1. Getting the jQuery Mobile Library
      2. Loading jQuery Mobile
    5. Configuring Browser Development Tools
      1. Installing Firebug on Firefox
      2. Enabling Developer Tools in Internet Explorer
      3. Enabling the JavaScript Console in Chrome
  11. 2. Using the JavaScript Language
    1. JavaScript Syntax
    2. Defining and Accessing Data
      1. Defining and Accessing Variables
      2. Creating Arrays
      3. Creating Objects
    3. Defining Functions
    4. Manipulating Strings
      1. Getting the Length of a String
      2. Finding What Character Is at a Specific Location in a String
      3. Converting Numbers to Strings
      4. Converting Strings to Numbers
      5. Combining Strings
      6. Changing String Case
      7. Splicing Strings
      8. Splitting Strings
      9. Checking to See If a String Contains a Substring
      10. Finding and Replacing Substrings Regardless of Case
    5. Manipulating Arrays
      1. Combining Arrays
      2. Splicing Arrays
      3. Detecting Whether an Array Contains an Item
      4. Removing Items from the Array
      5. Creating a Tab-Separated String from an Array
      6. Sorting Arrays
    6. Applying Logic
      1. Determining If an Object Is Equal To or Less Than Another
      2. Adding Conditional Blocks of Code
      3. Using a While Loop
      4. Iterating Through Arrays
      5. Iterating Through Object Properties
    7. Math Operations
      1. Generating Random Numbers
      2. Rounding Numbers
      3. Getting the Minimum Number in a Set
      4. Getting the Maximum Number in a Set
      5. Calculating Absolute Value
      6. Applying Trigonometric Functions
      7. Applying Power Functions
    8. Working with Dates
      1. Creating a Date Object
      2. Getting the Current Date and Time
      3. Creating a Date String
      4. Creating a Time String
      5. Getting a Time Delta
      6. Getting Specific Date Components
  12. 3. Interacting with the Browser
    1. Writing to the JavaScript Console
    2. Reloading the Web Page
    3. Redirecting the Web Page
    4. Getting the Screen Size
    5. Getting Current Location Details
      1. Finding the Current Hash
      2. Getting the Host Name
      3. Looking at the File Path
      4. Getting the Query String
      5. Determining If the Page Is Viewed on a Secure Protocol
    6. Accessing the Browser
      1. Getting the Max Viewable Web Page Size
      2. Setting the Text Displayed in the Browser Status Bar
      3. Getting the Current Location in the Web Page
      4. Opening and Closing Windows
    7. Using the Browser History to Go Forward and Backward Pages
    8. Creating Popup Windows
    9. Manipulating Cookies
      1. Setting a Cookie Value in the Browser
      2. Getting a Cookie Value from the Browser
      3. Example Getting and Setting Cookies
    10. Adding Timers
      1. Adding a Delay Timer
      2. Cancel a Timer
      3. Adding a Recurring Timer
  13. 4. Accessing HTML Elements
    1. Finding HTML Elements in JavaScript
      1. Finding DOM Objects by ID
      2. Finding DOM Objects by Class Name
      3. Finding DOM Objects by Tag Name
    2. Using the jQuery Selector to Find HTML Elements
      1. Applying Basic jQuery Selectors
      2. Selecting Elements Based on HTML Attributes
      3. Selecting Elements Based on Content
      4. Selecting Elements by Hierarchy Positioning
      5. Selecting Elements by Form Status
      6. Selecting Elements Based on Visibility
      7. Applying Filters in jQuery Selectors
    3. Chaining jQuery Object Operations
    4. Navigating jQuery Objects to Select Elements
      1. Getting the Children of Elements
      2. Getting the Closest Elements
      3. Getting the Elements Contained
      4. Finding Descendant Elements
      5. Getting Siblings That Come After Selected Objects
      6. Getting the Positioning Parents
      7. Finding the Parent or Ancestors of Selected Items
      8. Getting the Previous Siblings
      9. Getting Siblings
  14. 5. Manipulating the jQuery Object Set
    1. Getting DOM Objects from a jQuery Object Set
    2. Converting DOM Objects into jQuery Objects
    3. Iterating Through the jQuery Object Set Using .each()
    4. Using .map()
    5. Assigning Data Values to Objects
    6. Adding DOM Elements to the jQuery Object Set
    7. Removing Objects from the jQuery Object Set
    8. Filtering the jQuery Object Results
      1. Filtering Items Based on Index
      2. Filtering Selector Results Using a Filter Function
      3. Getting the First or Last Item
      4. Getting Items That Contain Other Items
      5. Filter Items Out Using Not Logic
      6. Slicing Up Selector Results
  15. 6. Capturing and Using Browser and User Events
    1. Understanding Events
      1. Reviewing Event Types
    2. Adding Event Handlers
      1. Adding a Page Load Event Handler in JavaScript
      2. Adding Initialization Code in jQuery
      3. Assigning an Event Handler in HTML
      4. Adding Event Handlers in JavaScript
      5. Removing Event Handlers in JavaScript
      6. Adding Event Handlers in jQuery
      7. Removing Event Handlers in jQuery
    3. Controlling Events
      1. Stopping Event Bubbling Up to Other Elements
      2. Stopping Default Behavior
      3. Triggering Events Manually in jQuery
    4. Using Event Objects
      1. Getting the Event Target Objects
      2. Getting the Mouse Coordinates
    5. Handling Mouse Events
      1. Adding Mouse-Click-Handling Code
      2. Handling the Mouse Entering or Leaving Elements
      3. Applying a Right-Click
    6. Handling Keyboard Events
      1. Detecting Changes to Text Input Elements
      2. Determining What Key Was Pressed
    7. Form Events
      1. Handling Focus Changes
      2. Handling Selection Changes
  16. 7. Manipulating Web Page Elements Dynamically
    1. Getting and Setting DOM Element Attributes and Properties
      1. Changing a Link Location
      2. Changing an Image Source File
    2. Getting and Setting CSS Properties
      1. Changing Colors
      2. Adding Borders
      3. Changing Fonts
      4. Adding a Class
      5. Removing a Class
      6. Toggling Classes
    3. Getting and Manipulating Element Content
      1. Getting the Content of an HTML Element
      2. Appending and Prepending Text to a Basic HTML Element
      3. Replacing Element Text
      4. Appending Elements to Parent Content
  17. 8. Manipulating Web Page Layout Dynamically
    1. Hiding and Showing Elements
    2. Adjusting Opacity
    3. Resizing Elements
    4. Repositioning Elements
    5. Stacking Elements
  18. 9. Dynamically Working with Form Elements
    1. Getting and Setting Text Input Values
    2. Checking and Changing Check Box State
    3. Getting and Setting the Selected Option in a Radio Group
    4. Getting and Setting Select Values
    5. Getting and Setting Hidden Form Attributes
    6. Disabling Form Elements
    7. Showing/Hiding Form Elements
    8. Forcing Focus to and Away from Form Elements
    9. Controlling Form Submission
  19. 10. Building Web Page Content Dynamically
    1. Creating HTML Elements Using jQuery
    2. Adding Elements to the Other Elements
      1. Prepending to the Beginning of an Element’s Content
      2. Appending to the Bottom of an Element’s Content
      3. Inserting into the Middle of an Element’s Content
      4. Adding Elements Example
    3. Removing Elements from the Page
    4. Dynamically Creating a Select Form Element
    5. Appending Rows to a Table
    6. Inserting Items into a List
    7. Creating a Dynamic Image Gallery
    8. Adding HTML5 Canvas Graphics
  20. 11. Adding jQuery UI Elements
    1. Adding the jQuery UI Library
    2. Implementing an Autocomplete Input
    3. Implementing Drag and Drop
    4. Adding Datepicker Element
    5. Using Sliders to Manipulate Elements
    6. Creating a Menu
    7. Adding Tooltips
  21. 12. Animation and Other Special Effects
    1. Understanding jQuery Animation
      1. Animating CSS Settings
      2. Understanding Animation Queues
      3. Stopping Animation
      4. Delaying Animation
    2. Animating Visibility
      1. Fading Elements In
      2. Fading Elements Out
      3. Toggling Element Visibility On and Off
      4. Fading to a Specific Level of Opacity
      5. Adding a Transition When Changing Images
    3. Making an Element Slide Back to Disappear
    4. Animating Show and Hide
      1. Animating hide()
      2. Animating show()
      3. Animating toggle()
    5. Animating Resizing an Image
    6. Animating Moving an Element
  22. 13. Using AJAX to Communicate with Web Servers and Web Services
    1. Understanding AJAX
      1. Understanding Asynchronous Communication
      2. Understanding Cross-Domain Requests
      3. Understanding GET versus POST Requests
      4. Understanding Response Data
    2. AJAX from JavaScript
      1. Geting an XMLHttpRequest Object
      2. Sending a GET Request from JavaScript
      3. Sending a POST Request from JavaScript
    3. AJAX from jQuery
      1. Loading HTML Data into Page Elements
      2. Using a jQuery .get() AJAX Request to Handle JSON Data
      3. Using a jQuery .get() AJAX Request to Handle XML Data
      4. Using a jQuery .post() AJAX Request to Update Server Data
    4. Handling jQuery AJAX Responses
    5. Using Advanced jQuery AJAX
      1. Changing the Global Setup
      2. Using Global Event Handlers
      3. Implementing Low-Level AJAX Requests
  23. 14. Implementing Mobile Web Sites with jQuery
    1. Getting Started with jQuery Mobile
      1. Determining if the Page Is Being Viewed on a Mobile Device
      2. Detecting Mobile Screen Size
      3. Specifying Different Theme Swatches
      4. Handling New Mobile Events
      5. Changing Pages with jQuery Code
      6. Loading Mobile Pages without Displaying Them
      7. Defining the Viewport Meta Tag
      8. Configuring jQuery Mobile Default Settings
    2. Building Mobile Pages
      1. Creating a Mobile Web Page
      2. Creating Fixed Headers and Footers
    3. Implementing Mobile Sites with Multiple Pages
      1. Adding Navigation Buttons
      2. Positioning Navigation Buttons
      3. Adding Page Change Transitions
      4. Creating a Back Button
      5. Changing Pages with Swipe Event Handlers
      6. Adding Navigation Buttons and Swipe Events Example
    4. Creating a Navbar
    5. Applying a Grid Layout
    6. Implementing Listviews
      1. Creating a Basic Listview
      2. Using Nested Lists
      3. Implementing Split Button List
      4. Adding Dividers to Lists
      5. Implementing a Searchable List
    7. Using Collapsible Blocks and Sets
    8. Adding Auxiliary Content to Panels
    9. Working with Popups
    10. Building Mobile-Friendly Tables
    11. Creating Mobile Forms
      1. Adding/Hiding Labels
      2. Disabling Form Elements
      3. Refreshing Form Elements
      4. Adding Form Elements
  24. Index

Product information

  • Title: jQuery and JavaScript Phrasebook
  • Author(s):
  • Release date: December 2013
  • Publisher(s): Addison-Wesley Professional
  • ISBN: 9780321918963