event

  • Revision slug: Talk:Document_Object_Model_(DOM)/event
  • Revision title: event
  • Revision id: 164219
  • Created:
  • Creator: Jan Dudek
  • Is current revision? No
  • Comment

Revision Content

There needs to be a section on how HTML event attribute strings are evaluated. For ex:

<button ... onclick="foo();">

creates a function named "onclick" with the event object as a parameter named event:

function onclick(event) {
   foo();
}

See Core_JavaScript_1.5_Reference:Objects:Function#Functions_as_event_handlers.

--Maian 03:30, 8 September 2005 (PDT)

Actually, onclick="foo();" will assign the RESULT of the function "foo" to onclick, unless I am misunderstanding something. --Callek 20:20, 15 September 2005 (PDT)
You're misunderstanding something :) That would make no sense, since most handlers return either nothing (undefined) or a boolean, and you don't set onclick to undefined or boolean. Try alert(button.onclick) for proof. --Maian 00:15, 16 September 2005 (PDT)
Do NOTE my use of () in the "actually" clause there, button.onclick is different from button.onclick(); as in, adding the paren's to the attribute changes its meaning, I'll check this out for sure later, been a while since I played with the HTML side of any script-related pages. Though realize, if I was 100% sure, I would have simply fixed any problem I found. --Callek 22:45, 20 September 2005 (PDT)
Callek, in your example, "foo()" is a string, so you're really misunderstanding (or mistyping) something. --Nickolay 02:31, 21 September 2005 (PDT)


Why is there no description of event.originalTarget ? Versgui 16:21, 20 July 2006 (PDT)

Because no-one wrote it yet. I added them to the list, feel free to put content on those pages. --Nickolay 01:33, 21 July 2006 (PDT)

Is the section on event methods incomplete? See Notes on http://developer.mozilla.org/en/docs/DOM:document.createEvent Jabez

I am working on a Polish translation of the Gecko DOM Ref and after a closer look at docs I've got some suggestions. I think we need at least two things described clearly and completely, in one proper place. These are

  • propagation phases
  • how to register events.

As far as I have seen (maybe I missed something?) there is no clear explanation of propagation phases - what is "bubbling" and "capture", what comes when. The diagram in the introduction is a good resource, but not in this place. I would suggest putting it all in a separate section or separate page.

The second thing is how to register event handlers. Three possible ways of doing it should be clearly explained on one page. I mean element.addEventListener(), element.onsomething properties and HTML onsomething="" attribute. The info about wrapper function for the HTML attribute code should include information about predefined "event" parameter (which is currently in the DOM:event). There is needed a clarification which are pros and cons of those different methods. Something in this direction is in DOM:element.onclick#Notes.

There is also a document.createEvent method which is related to events and could by mentioned in the event model description.

I don't want to criticise, I just think we need a better description of event model, easy to understand for people new to DOM.

My suggestion is to put all important information in one place and to make it complete - just avoid splitting information on different pages. --Jan Dudek 04:59, 3 August 2006 (PDT)

Revision Source

<p>There needs to be a section on how HTML event attribute strings are evaluated. For ex:
</p>
<pre>&lt;button ... onclick="foo();"&gt;
</pre>
<p>creates a function named "onclick" with the event object as a parameter named <code>event</code>:
</p>
<pre>function onclick(event) {
   foo();
}
</pre>
<p>See <a href="en/Core_JavaScript_1.5_Reference/Objects/Function#Functions_as_event_handlers">Core_JavaScript_1.5_Reference:Objects:Function#Functions_as_event_handlers</a>.
</p><p>--<a href="User:Maian">Maian</a> 03:30, 8 September 2005 (PDT)
</p>
<dl><dd> Actually, onclick="foo();" will assign the RESULT of the function "foo" to onclick, unless I am misunderstanding something. --<a href="User:Callek">Callek</a> 20:20, 15 September 2005 (PDT)
</dd></dl>
<dl><dd><dl><dd> You're misunderstanding something :) That would make no sense, since most handlers return either nothing (undefined) or a boolean, and you don't set onclick to undefined or boolean. Try <code>alert(button.onclick)</code> for proof. --<a href="User:Maian">Maian</a> 00:15, 16 September 2005 (PDT)
</dd></dl>
</dd></dl>
<dl><dd><dl><dd> Do <b>NOTE</b> my use of () in the "actually" clause there, button.onclick is different from button.onclick();  as in, adding the paren's to the attribute changes its meaning, I'll check this out for sure later, been a while since I played with the HTML side of any script-related pages. Though realize, if I was 100% sure, I would have simply fixed any problem I found. --<a href="User:Callek">Callek</a> 22:45, 20 September 2005 (PDT)
<dl><dd> Callek, in your example, <code>"foo()"</code> is a string, so you're really misunderstanding (or mistyping) something. --<a href="User:Nickolay">Nickolay</a> 02:31, 21 September 2005 (PDT)
</dd></dl>
</dd></dl>
</dd></dl>
<p><br>
Why is there no description of <b>event.originalTarget</b> ?
<a href="User:Versgui">Versgui</a> 16:21, 20 July 2006 (PDT)
</p>
<dl><dd> Because no-one wrote it yet. I added them to the list, feel free to put content on those pages. --<a href="User:Nickolay">Nickolay</a> 01:33, 21 July 2006 (PDT)
</dd></dl>
<p>Is the section on event methods incomplete? See Notes on http://developer.mozilla.org/en/docs/DOM:document.createEvent <a href="User:Jabez">Jabez</a>
</p><p>I am working on a Polish translation of the Gecko DOM Ref and after a closer look at docs I've got some suggestions.
I think we need at least two things described clearly and completely, in one proper place. These are
</p>
<ul><li> propagation phases
</li><li> how to register events.
</li></ul>
<p>As far as I have seen (maybe I missed something?) there is no clear explanation of propagation phases - what is "bubbling" and "capture", what comes when. The diagram in the introduction is a good resource, but not in this place. I would suggest putting it all in a separate section or separate page.
</p><p>The second thing is how to register event handlers. Three possible ways of doing it should be clearly explained on one page. I mean element.addEventListener(), element.onsomething properties and HTML onsomething="" attribute. The info about wrapper function for the HTML attribute code should include information about predefined "event" parameter (which is currently in the DOM:event). There is needed a clarification which are pros and cons of those different methods. Something in this direction is in <a href="en/DOM/element.onclick#Notes">DOM:element.onclick#Notes</a>.
</p><p>There is also a <a href="en/DOM/document.createEvent">document.createEvent</a> method which is related to events and could by mentioned in the event model description.
</p><p>I don't want to criticise, I just think we need a better description of event model, easy to understand for people new to DOM.
</p><p>My suggestion is to put all important information in one place and to make it complete - just avoid splitting information on different pages.
--<a href="User:Jan_Dudek">Jan Dudek</a> 04:59, 3 August 2006 (PDT)
</p>
Revert to this revision