Question

When an event, such as onclick, is declared in a col element for an HTML table does that event impact the cells referenced by the col element? Is the event ignored? Does something else happen?

Was it helpful?

Solution

Great question.

The spec says:

<!ATTLIST COL                          -- column groups and properties --
  %attrs;                              -- %coreattrs, %i18n, %events ---

where %events says:

<!ENTITY % events
 "onclick     %Script;       #IMPLIED  -- a pointer button was clicked --
  ondblclick  %Script;       #IMPLIED  -- a pointer button was double clicked--
  onmousedown %Script;       #IMPLIED  -- a pointer button was pressed down --
  onmouseup   %Script;       #IMPLIED  -- a pointer button was released --
  onmouseover %Script;       #IMPLIED  -- a pointer was moved onto --
  onmousemove %Script;       #IMPLIED  -- a pointer was moved within --
  onmouseout  %Script;       #IMPLIED  -- a pointer was moved away --
  onkeypress  %Script;       #IMPLIED  -- a key was pressed and released --
  onkeydown   %Script;       #IMPLIED  -- a key was pressed down --
  onkeyup     %Script;       #IMPLIED  -- a key was released --"
  >

So yes, it appears events are supposed to be supported for the tds.

However "supposed to" is a far cry from "does". The only way to know is to test in all browsers and hope it works in future browsers too.

On second thought, just use event delegation and bind once to the parent table instead. That will work now and forever more.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top