June 13, 2011 1:15 PM
"Why isn't addEventListener working in Firefox?" and the Difference Between Event Capturing & Event Bubbling:
Like the last two posts below, this one has a really simple answer but I figured I would post this just in case someone runs into the same problem.
You might be getting a cryptic error like the following:
On Chrome & Safari, addEventListener() won't complain if you only pass in two arguments. But on Firefox, it requires three:
The Difference Between Event Capturing & Event Bubbling:
When should you use 'true' as the third argument to addEventListener() and when should you use 'false'? Well, it depends on whether you want the handler function (foo) to fire in the bubbling phase or the capturing phase. What's the difference between the two?
Peter Paul-Koch from Quirksmode has a far more detailed explanation, but here's the short version: if you have a parent element and a child element both listening for the same event, with capturing set to "true" (the third argument), the parent's event handler will fire off first before the child's event handler. If you set capturing to "false" (as we did in the example above), the child's event handler will fire first before the parent's handler. If you're only going to have one element listening to a specific event, then "false" is fine.
For example, if you used the following, parent_element's handler would run first: