[Restored attribution lines]
[Thomas 'PointedEars' Lahn wrote:]
Entirely irrelevant here. And you are confused about the meaning of
‘this’ in functions called from event-handler attributes.
[...]
Thank you for trying to trim to what is relevant. But please include/leave
in an attribution line for each quotation level (because it's relevant).
Please don't quote signatures if you are not explicitly referring to their
content (because they are not relevant then). Please get a real name by
subscribing to the newsgroup (and updating your profile there), or
(recommended) by not using Google Groups for posting but a decent locally
installed newsreader application (e.g., Mozilla Thunderbird or KNode).
Thomas, these postings have left me confused. I generate the HTML from a
database and have complete control over the content. Based on what
everyone seems to be saying, I have to wrap every single word with a
handler and or ID. Am I on the wrong track?
I'm afraid so. Since you have "complete control over the content" and the
`click' event bubbles in all known DOMs, it is unwise of you to add the
listener dynamically (with the element type identifier or the element IDs as
point of reference), to pay (efficiency-wise) for necessary branching for
each `span' element, and to risk its not working properly despite all these
efforts (for several reasons discussed before).
Instead, you should use the event-handler attribute as in my example which
so far is known to work reliably and consistently among browsers/DOMs.
Simply try it out with a <span>word</span> to see how it works. (If you
can't get console.log() to work at first, use window.alert() instead.) Of
course, you need to test the `tagName' property case-insensitively, and you
may use the `class' attribute (and `className' property), so that you only
consider relevant `span' elements.
See also:
<
http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow>
<
http://www.w3.org/TR/2003/NOTE-DOM-Level-3-Events-20031107/events.html#Events-flow>
Please take notice that W3C DOM Level 3 Events is not a Recommendation yet,
but its event flow definition is much the same as in W3C DOM Level 2 Events
which is a REC, and the definition in L3 are easier to understand
(especially for beginners) because of the graphical representation.
These can quickly become complex issues, rather difficult to explain to a
beginner (because of all the technobabble that is needed). Nevertheless, I
shall try to set you on the right track so that the scripts you're going to
write are considerably better than what most of the wannabes on the Web and
in books produce nowadays. To that end, I do hope I could clarify, and not
add to, your confusion
(What I mean above is that Garrett is confused as to the meaning of `this'
within the called function in my supplemental, bodyClick(). Since that
function is not an event listener but only *called from* an event listener,
`this' within it refers refers to the Global Object [of which it is a
method] always. However, `this' within the event listener created by the
event-handler attribute value, `onclick', (which does not occur here there)
has different meaning depending on the browser/DOM because the `body'
element has a known peculiarity there.
If you don't understand what all that means, you may, but do not need to,
ignore it for the time being.)
By the way, I am a relative Javascript newbie even though I've read the
book twice.
Which book? Chances are you've read a bad book anyway.
PointedEars