views:

1513

answers:

3

I'm using event delegation to listen for events lower in the DOM, but it's not working for an onchange event on a select box. Does the onchange event propagate or bubble up the DOM?

Googling has failed in finding a conclusive answer.

A: 

Not sure if I get the question, but if you mean this, then NO.

<div id="foo">
  <select onchange="alert('hi');">
    <option>Hello</option>
    <option>World</option>
  </select>
</foo>

Where the div id="foo" would have an onchange event... bubbling up from the select list?


on a related note, just an FYI you can't attach an event to the options within the select list in IE (well, you can but it won't fire)

scunliffe
A: 

I haven't dealt with this for quite a while, but last time I did, I remember that Firefox recognized the event on the <SELECT> element, while IE6 recognized only events on the <OPTION> tags. As far as I remember.

IE7 was not out at that time.

So if this is the case, it makes even more sense to not write the event handler inline and apply it on DOM ready instead, lest you are going to have a lot of polluted, repetitive code.

schonarth
No IE has a bug in that it doesn't register events on the <option> elements at all (IE6, IE7, IE8) see bug report and test page here:http://webbugtrack.blogspot.com/2007/11/bug-280-lack-of-events-for-options.html
scunliffe
+9  A: 

No, "change" event does not bubble. Also, events: change, submit, reset, focus, blur do not bubble in Internet Explorer. According to specification, "focus" and "blur" should not bubble, while "change", "submit", "reset" should, this behavior implemented properly in all web browsers but IE.

Sergey Ilinsky