I\'ve got a page with a variable number of elements (which explains why I\'m using event delegation here). When the user changes the selected opt
The change
event does not bubble in IE (See here and here). You cannot use event delegation in tandem with it.
In fact, it is because of this IE bug that jQuery .[1]live
had to officially exclude change
from the list of supported events (FYI the DOM spec states change
should bubble)
With respect to your question, you can bind directly to each select:
$('#container select').change(/*...*/)
If you really want event delegation you might find some success trying what this person did and bind to click
in IE only, which does bubble:
$('#container').bind($.browser.msie ? 'click' : 'change', function(event) {
/* test event.type and event.target
* to capture only select control changes
*/
})
But this browser detection feels really wrong. I'd really try working with the former example (binding directly to the drop downs). Unless you have hundreds of <select>
boxes, event delegation wouldn't buy you much here anyway.
[1] Note: jQuery >= 1.4 now simulates a bubbling change
event in IE via live()/on().
I'm trying to understand why you need to double check the name of the select after receiving an event to it.
Do you by any chance have multiple elements with the same id ?
Did you actually mean to say "#container select" instead of "#container" ?
onchange=doAction
will work in IE and Firefox, but its not supported in Chrome.
You need to use jQuery's .change
event to handle this.
IE requires change event to be placed inside document ready. This seems to bind the change event to the associated element. Hope it helps.