click
bubbles. So just bind to the <body>
and check what the target
of the event element is (you'll need to do a bit of event normalization to get around IE being different from everyone else.)
event.target
is the actual DOM element, so you can filter on anything that you want to filter on at that point.
This has the advantage that it doesn't matter how many elements are on the page, you only need one event handler for all of them. (Which means performance will be better on pages with hundreds or thousands of elements.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…