tags:

views:

93

answers:

2

Using jQuery, how can I make it so that a function is called whenever any select object on the page is changed? All of my select inputs are added to the HTML by ajax functions.

A: 
$("select").live("change", function(){
    //...
});
Y. Shoham
+1  A: 

As Y. Shoham says, it's the live function that you are looking for. However, look closely at the documentation, change is not supported in jQuery <= 1.3.2. Should be working as of jQuery 1.4.

And, yea, it should go without saying you can simply bind to the change event of the new elements whenever you add them. This is obviously not ideal from a code-complexity stand-point but does work ok. Just remember not to rebind the ones that already exist (unless you unbind them all first -- a waste of cycles IMO).

thenduks
It works in Chrome/Mozilla, but not IE. huh
Brian
So you can use `bind` instead, and assign it any time you add new `select` s to the page. To avoid duplicate event calls, you can unbind+bind at each assignment.
Y. Shoham