Description
“Take control with the ultimate JavaScript toolkit”
Among the 101 Tips, Tricks & Hacks you'll learn how-to:
- Create a slick yet accessible drop-down menu system
- Take control of your web pages with the DOM
- Validate forms in real time using regular expressions
- Optimize your code so that it runs faster
- Manage style sheets and modify styles on-the-fly
- Produce sophisticated drag-and-drop interaction
- Enhance your site with slick, animated transitions
- Create AJAX applications with the XMLHttpRequest object
…and much more. Far too many things to mention here!
Table of Contents
- Preface
- Who Should Read this Book?
- What’s in this Book?
- The Book’s Web Site
- The Code Archive
- Updates and Errata
- The SitePoint Forums
- The SitePoint Newsletters
- Your Feedback
- Acknowledgements
- Getting Started with JavaScript
- JavaScript Defined
- JavaScript’s Limitations
- Security Restrictions
- JavaScript Best Practices
- Providing for Users who Don’t Have JavaScript (Progressive Enhancement)
- Separating Content from Behavior (Unobtrusive Scripting)
- Using Braces and Semicolons (Consistent Coding Practice)
- Adding a Script to a Page
- Putting HTML Comments Around Code
- The language Attribute
- Getting Multiple Scripts to Work on the Same Page
- Hiding JavaScript Source Code
- Debugging a Script
- Understanding a Browser’s Built-in Error Reporting
- Using alert
- Using try-catch
- Writing to the Page or Window
- Using an External Debugger
- Strict Warnings
- Summary
- Working with Numbers
- Doing Math with JavaScript
- Rounding a Number to x Decimal Places
- Creating and Constraining Random Numbers
- Converting a Number to a String
- Formatting Currency Values
- Converting a String to a Number
- Converting Numbers to Ordinals (-st, -nd, -rd, -th)
- Summary
- Working with Strings
- Including a Special Character in a String
- Transforming the Character Case of a String
- Encoding a URL
- Comparing Two Strings
- Finding a Substring within a String
- Splitting a String into Substrings
- Creating a Regular Expression
- Testing whether a String Matches a Regular Expression
- Testing whether a String Contains Only Numeric Data
- Testing whether a String is a Valid Phone Number
- Testing whether a String is a Valid Email Address
- Searching and Replacing Text using a Regular Expression
- Summary
- Working with Arrays
- Using Array-literals
- Creating an Array of Arrays
- Indexing an Array with Strings Instead of Numbers
- Turning an Array into a String
- Adding or Removing Members from an Array
- Sorting an Array into Alphabetical or Numeric Order
- Sorting a Multi-dimensional Array
- Sorting an Array Randomly
- Summary
- Navigating the Document Object Model
- Accessing Elements
- Creating Elements and Text Nodes
- Changing the Type of an Element
- Removing an Element or Text Node
- Reading and Writing the Attributes of an Element
- Getting all Elements with a Particular Attribute Value
- Adding and Removing Multiple Classes to/from an Element
- Summary
- Processing and Validating Forms
- Reading and Writing the Data in a Text Field
- Reading and Setting the State of a Checkbox
- Reading and Setting the State of a Radio Button
- Reading and Setting the Value of a Select Box
- Validating a Mandatory Text Field
- Validating a Numeric Field
- Validating an Email Address Field
- Checking for Unselected Radio Buttons
- Stopping a Form Being Submitted Unless all its Fields are Valid
- Validating a F