Chapter 12: Cutting through attributes, properties and CSS
12.1 DOM attributes and properties
12.1.1 Cross-browser naming
12.1.2 Naming restrictions
12.1.3 XML differences from HTML
12.1.4 Behavior of custom attributes
12.1.5 Performance considerations
12.2 Cross-browser attribute issues
12.2.1 DOM id/name expansion
12.2.2 URL normalization
12.2.3 The style attribute
12.2.4 The type attribute
12.2.5 The tab index problem
12.2.6 Node names
12.3 Styling attribute headaches
12.3.1 Where’re my styles?
12.3.2 Style property naming
12.3.3 The float style property
12.3.4 Conversion of pixel values
12.3.5 Measuring heights and widths
12.3.6 Seeing through opacity
12.3.7 Riding the color wheel
12.4 Fetching computed styles
12.5 Summary
Chapter 13: Surviving events
13.1 Binding and unbinding event handlers
13.2 The event object
13.3 Handler management
13.3.1 Centrally storing associated information
13.3.2 Managing event handlers
13.4 Triggering events
13.4.1 Custom events
13.5 Bubbling and delegation
13.5.1 Delegating events to an ancestor
13.5.2 Working around browser deficiencies
13.6 The document ready event
13.7 Summary
Chapter 14: Manipulating the DOM
14.1 Injecting HTML into the DOM
14.1.1 Converting HTML to DOM
14.1.2 Inserting into the document
14.1.3 Script execution
14.2 Cloning elements
14.3 Removing elements
14.4 Text contents
14.4.1 Setting text
14.4.2 Getting text
14.5 Summary
Chapter 15: CSS selector engines
15.1 The W3C Selectors API
15.2 Using XPath to find elements
15.3 The pure DOM implementation
15.3.1 Parsing the selector
15.3.2 Finding the elements
15.3.3 Filtering the set
15.3.4 Recursing and merging
15.3.5 Bottom Up Selector Engine
15.4 Summary
Nội dung
[...]... some developers’ poor initial reaction to JavaScript may be that most developers are introduced to JavaScript in the browser So rather than reacting to JavaScript, The Language, they may be recoiling from theJavaScript bindings to the DOM API And the DOM API… well, let’s just say that it isn’t going to win any Friendliest API ofthe Year awards But that’s not JavaScript s fault Before we learn about... queue (a FIFO list, more on that later) as they occur, and the browser dispatches these events by invoking any handlers that have been established for them Because these events happen at unpredictable times and in an unpredictable order, we say that the handling ofthe events, and therefore the invocation of their handling functions, is asynchronous The types of events that can occur include: Browser... first-class objects How the browser invokes function Declaring functions The secretsof how functions are invoked The context within a function You might have been somewhat surprised, upon turning to this first page ofthe part of this book dedicated to JavaScript fundamentals, to see that the topic of discussion is to be functions rather than objects We’ll certainly be paying plenty of attention to... pull it off, we need not only a mastery of theJavaScript language, but a thorough knowledge ofthe browsers, along with their quirks and inconsistencies, and a good grounding in accepted best practices While JavaScript development can certainly be challenging, there are those brave souls who have already gone down this torturous route: the developers ofJavaScript libraries We’ll be distilling the knowledge... written to the console and be browsed immediately or at a later time without impeding the normal flow ofthe program – something not possible with alert() For example, if we wanted to know what the value of a variable named x was at a certain point in the code, we might write: console.log(x); If we were to assume that the value of x is 213, then the result of executing this statement in the Chrome... (If the notation used to create the function looks odd to you, be assured that we’ll be making it crystal clear in section 3.2.) Unobtrusive JavaScript This approach of assigning a function, named or otherwise, to the onload property ofthe window instance may not be the way that you are used to setting up a load handler You may be more accustomed to using the onload attribute ofthe tag Either... we also have the problem of determining if our code works in all the browsers that we choose to support We'll further discuss the problem of cross-browser development in-depth when we look at cross-browser strategies in chapter 11, but for now, it's vital that the importance of testing be emphasized and testing strategies defined, as we'll be using these strategies throughout the rest ofthe book In... objects (particularly in chapter 6), but when it comes down to brass tacks, the main difference between writing JavaScript code like the average Joe (or Jill) and writing it like a JavaScript Ninja, is understand JavaScript as a functional language The level of the sophistication of all the code that you will ever write in JavaScript hinges upon this realization If you’re reading this book, you’re... markup, CSS, or JavaScript as we can without disrupting the intent of the test case The more that we remove, the greater the likelihood that the test case will only be influenced by the specific code that we are trying to test • Independence – our tests should execute in isolation We must strive to not make the results from one test be dependent upon another We should break tests down into their smallest... JSUnit JSUnit is a port ofthe popular Java JUnit testing framework to JavaScript While it's still one ofthe most popular JavaScript unit testing frameworks around, JSUnit is also one ofthe oldest (both in terms ofthe code base age and quality) The framework hasn't been updated much recently, so for something that's known to work with all modern browsers, JSUnit may not be the best choice More information . the choices of those in the decision-
making process, taking into account factors such as the skill of the developers, the needs of
the market, and other. multiple considerations, the primary of which are:
The market share of the browser
The amount of effort necessary to support the browser
Figure 1.2