An obscure problem worth noting here may also be this fact I just discovered:
If an element has z-index
set to -1
or smaller, you may think the
listener is not being bound, when in fact it is, but the browser
thinks you are clicking on a higher z-index
element.
The problem, in this case, is not that the listener isn't bound, but instead it isn't able to get the focus, because something else (e.g., perhaps a hidden element) is on top of your element, and that what get's the focus instead (meaning: the event is not being triggered). Fortunately, you can detect this easily enough by right-clicking the element, selecting 'inspect' and checking to see if what you clicked on is what is being "inspected".
I am using Chrome, and I don't know if other browsers are so affected. But, it was hard to find because functionally, it resembles in most ways the problem with the listener not being bound. I fixed it by removing from CSS the line: z-index:-1
;
body
element (e.g., as anonclick
attribute) or else run the risk of blowing away listeners that are already there. An event delegation strategy is far more safe: less likely to interfere with or clobber other listeners on the element, and less likely to hog memory with per-element listeners. – Excerpta