views:

39

answers:

1

Since events bubble up in the DOM, it seems like a change event should be able to reach any container element (e.g. div, table, or ul elements). Therefore, it seems like any such elements should support the onchange attribute. However, it seems like only a few element types support this in the official standard.

Despite this, I was able to give a tbody an onchange attribute, which ran when I changed the contents of a text input within the tbody.

Will I experience the same thing if I use some other major browser + OS combination?

+3  A: 

As described in the DOM Level 2 Events Specification, the change event is valid only for INPUT, SELECT, and TEXTAREA elements.

Edit: As @no kindly comments, the event according the W3C Standard bubbles up, the purpose of this is clearly to catch the event on other elements.

But I wouldn't recommend you to expect cross-browser bubbling with change for one reason: IE.

In their proprietary Event Model implementation, they explicitly describe that the change event does not bubble...

CMS
As I stated in my question, I'm already familiar with the fact that only a few element types support this attribute. My question is, What actually happens in practice?
allyourcode
@allyourcode You should rarely, if ever, rely on non-standard functionality.
George Marian
CMS: The spec is a bit confusing here. It says that the `change` event is only valid for the elements you listed, but right under that it says the change event bubbles. Since none of those elements can be nested inside of each other, it can be assumed that the reason for bubbling is to catch the event on non-input-like elements... if this isn't the intended behavior, the spec would have made this a non-bubbling event. It seems the correct interpretation of the spec is that the change event should be catchable on parent elements of the `input`, `select`, or `textarea` the event originated from.
no
CMS: shh... maybe if we ignore IE it will just quietly go away...
no
@no, hehe, IE... isn't strange? they do exactly the opposite from W3C...
CMS