Does the onchange event propagate?

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.

Answers:

Answer

In jQuery 1.4+ the change event bubbles in all browsers, including IE.

$('div.field_container').change(function() {
   // code here runs in all browers, including IE.
});
Answer

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.

Answer

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)

Answer

According to specification, change, submit, reset should bubble and focus and blur should not bubble.

This behavior is implemented properly in all web browsers except IE < 9, that is, change, submit, reset do bubble properly in IE >= 9.

See https://stackoverflow.com/a/4722246/227299 for a jQuery workaround on old IE versions

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.