![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
You can use event.target/event.srcElement to determine the clicked node and check if it is inside the table. Then you can use cellIndex and rowIndex properties of the cell and row to get the coordinates. |
#4
| |||
| |||
|
|
On May 18, 11:37 pm, "P. Prikryl" <p.prik... (AT) gmail (DOT) com> wrote: You can use event.target/event.srcElement to determine the clicked node and check if it is inside the table. Then you can use cellIndex and rowIndex properties of the cell and row to get the coordinates. For Google food, this has been termed "event delegation" meaning a parent element is watching for events that bubble up from child elements. http://yuiblog.com/blog/2007/01/17/event-plan/ http://developer.yahoo.com/yui/examp...elegation.html |
#5
| |||
| |||
|
|
You can use event.target/event.srcElement to determine ... |
#6
| |||
| |||
|
|
Q1: Why is "TD" capitalized? I understand that HTML is case-insensitive whereas JS is sensitive. The == comparison is done at the JS level; how did you know to use uppercase? |
|
"a"=="A" false "A"=="A" true |
|
Q2: Why 3 levels of parentNode, rather than 2, in tdvar.parentNode.parentNode.parentNode == this |
#7
| |||
| |||
|
|
Peter Michaux wrote: On May 18, 11:37 pm, "P. Prikryl" <p.prik... (AT) gmail (DOT) com> wrote: You can use event.target/event.srcElement to determine the clicked node and check if it is inside the table. Then you can use cellIndex and rowIndex properties of the cell and row to get the coordinates. For Google food, this has been termed "event delegation" meaning a parent element is watching for events that bubble up from child elements. http://yuiblog.com/blog/2007/01/17/event-plan/ http://developer.yahoo.com/yui/examp...elegation.html However, the technically correct no-buzzword term is "Event bubbling" (mentioned here before) or, more generally, "Event dispatch": http://www.w3.org/TR/DOM-Level-2-Eve...vents-20071221 |
#8
| ||||||||
| ||||||||
|
|
On May 19, 2:37 am, "P. Prikryl" <p.prik... (AT) gmail (DOT) com> wrote: You can use event.target/event.srcElement to determine ... Thank you (dziekuje bardzo) P. Prikryl, Peter and Thomas. |
|
[...] script language="JavaScript" |
|
function UpdateGame(x,y) {alert("USER clicked (" + x + "," + y + ").")}; document.getElementById("GameTable").onclick = function(e) { |
|
e = e || window.event; |
|
for (var tdvar = e.target || e.srcElement; tdvar && tdvar != this; tdvar = tdvar.parentNode) if (tdvar.tagName == "TD" && tdvar.parentNode.parentNode.parentNode == this) { UpdateGame(tdvar.parentNode.rowIndex, tdvar.cellIndex); break; } }; /script Q1: Why is "TD" capitalized? I understand that HTML is case-insensitive whereas JS is sensitive. The == comparison is done at the JS level; how did you know to use uppercase? |
|
Q2: Why 3 levels of parentNode, rather than 2, in tdvar.parentNode.parentNode.parentNode == this ? Is it that `tdvar' is bound to an event whose parent is TD>? |
|
Or is it that `tdvar' is bound to <TD>, |
|
but that an implicit <TBODY> is being inserted into my innocent table>? |
#9
| |||
| |||
|
|
On May 19, 6:23 am, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de wrote: Peter Michaux wrote: On May 18, 11:37 pm, "P. Prikryl" <p.prik... (AT) gmail (DOT) com> wrote: You can use event.target/event.srcElement to determine the clicked node and check if it is inside the table. Then you can use cellIndex and rowIndex properties of the cell and row to get the coordinates. For Google food, this has been termed "event delegation" meaning a parent element is watching for events that bubble up from child elements. http://yuiblog.com/blog/2007/01/17/event-plan/ http://developer.yahoo.com/yui/examp...elegation.html However, the technically correct no-buzzword term is "Event bubbling" (mentioned here before) or, more generally, "Event dispatch": http://www.w3.org/TR/DOM-Level-2-Eve...vents-20071221 "Event bubbling" is the mechanics of the chain of responsibility pattern implemented in the DOM. It is just the fact that an event does bubble. "Event delegation" is an application-level concept of how a bubbling event is used. If a ancestor node is handling an event on behalf of a node that would normally handle the event itself then that is event delegation. Event bubbling is what makes event delegation possible. |
#10
| |||
| |||
|
|
Must be at least script type="text/javascript" The `language' attribute is deprecated, the `type' attribute is required: |
|
Q1: Why is "TD" capitalized? ... See <http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-822762427>. However, as XHTML may also be served as text/html in which case it may be parsed as HTML, I consider case-insensitive matching to be less error-prone: if (tdvar.tagName.toLowerCase() == "td" ...) |
![]() |
| Thread Tools | |
| Display Modes | |
| |